Loading ...
Sorry, an error occurred while loading the content.

Preventing Double maps/abbs

Expand Messages
  • howard Schwartz
    I recently discovered a pitfall similar to recursive abbreviations or maps (in math logic we would would tend to call them `transitive instead of recursive).
    Message 1 of 7 , Feb 2, 2012
    • 0 Attachment
      I recently discovered a pitfall similar to recursive abbreviations or maps (in
      math logic we would would tend to call them `transitive' instead of recursive).

      As you know, noremap prevents map a b then map b c thus mapping a to c

      But a ran into this dilemma: my friend used these abbreviations and maps:

      ab q can map q i ^[
      ab gr gramma map g :write^M

      thus eliminating the gq formatting command. When I tried to restore it, I
      first tried to unmap q

      I got the error message, ``No such mapping'' even though the maps command
      clearly listedd q as mapped to write. I quickly learned I had to
      unabbreviate q before I could unmap q. Similar things applied to the letter g
      in order to recover he command gq.

      What seems to happen is an interaction between abbreviations and maps: When I
      gave the ex command :q <ENTER> upon hitting <ENTER> vim expands q to `can' and
      then treats `can' as a write command. When I try to unmap q, I press
      <ENTER>. Thus,
      q expands to `can' and vim correctly replies ``no such mapping'' meaning
      there is no direct map of the latters `can' to a write command.


      Multiple abbreviations or maps of the same letters is not a problem, within
      maps or ab alone -- ordinarily last definition wins.

      What seems to be needed is a version of abbreviate that says ``only abbreviate
      these letters, do not use them to map a command''. The modes for maps and ab
      do not help, because sometimes one really wants letters expanded on the
      command line, for example when executing a substitute command.

      And, in general it is an advantage to be able to use the same strings of 1 or
      two characters, as both maps and appreviations. For `rabid' abbreviators like
      my friend, this gives one more letters to do more things.

      Is there some way to prevent this behaviour for some, particular maps or
      abbreviations?

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Jürgen Krämer
      Hi, ... it would probably have been better if your friend had used iabbrev q can iabbrev gr gramma nmap q i ^[ nmap g :write^M to define the abbreviations
      Message 2 of 7 , Feb 2, 2012
      • 0 Attachment
        Hi,

        howard Schwartz wrote:
        > I recently discovered a pitfall similar to recursive abbreviations or maps (in
        > math logic we would would tend to call them `transitive' instead of recursive).
        >
        > As you know, noremap prevents map a b then map b c thus mapping a to c
        >
        > But a ran into this dilemma: my friend used these abbreviations and maps:
        >
        > ab q can map q i ^[
        > ab gr gramma map g :write^M
        >
        > thus eliminating the gq formatting command. When I tried to restore it, I
        > first tried to unmap q

        it would probably have been better if your friend had used

        iabbrev q can
        iabbrev gr gramma
        nmap q i ^[
        nmap g :write^M

        to define the abbreviations and maps, thus restricting them to the modes
        where they are really needed.

        > I got the error message, ``No such mapping'' even though the maps command
        > clearly listedd q as mapped to write. I quickly learned I had to
        > unabbreviate q before I could unmap q. Similar things applied to the letter g
        > in order to recover he command gq.
        >
        > What seems to happen is an interaction between abbreviations and maps: When I
        > gave the ex command :q <ENTER> upon hitting <ENTER> vim expands q to `can' and
        > then treats `can' as a write command. When I try to unmap q, I press
        > <ENTER>. Thus,
        > q expands to `can' and vim correctly replies ``no such mapping'' meaning
        > there is no direct map of the latters `can' to a write command.

        For me Vim's reply is

        E492: Not an editor command: can

        No remapping took place, but "can" is not a recognized command.

        > Multiple abbreviations or maps of the same letters is not a problem, within
        > maps or ab alone -- ordinarily last definition wins.
        >
        > What seems to be needed is a version of abbreviate that says ``only abbreviate
        > these letters, do not use them to map a command''. The modes for maps and ab
        > do not help, because sometimes one really wants letters expanded on the
        > command line, for example when executing a substitute command.

        There are also [ic]noreabbrev variants which would prevent the
        right-hand-side of an abbreviation to be re-used as the left-hand-side
        of a mapping.

        Regards,
        Jürgen

        --
        Sometimes I think the surest sign that intelligent life exists elsewhere
        in the universe is that none of it has tried to contact us. (Calvin)

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • howardb21
        ... Where do I find these variants? I searched Vim s documentation and only found versions of nore that prevent re-use of the right had side of a map or
        Message 3 of 7 , Feb 4, 2012
        • 0 Attachment
          On Feb 2, 10:26 pm, Jürgen Krämer <jottka...@...> wrote:
          > Hi,
          >
          > There are also [ic]noreabbrev variants which would prevent the
          > right-hand-side of an abbreviation to be re-used as the left-hand-side
          > of a mapping.

          Where do I find these variants? I searched Vim's documentation and
          only found versions of nore that prevent re-use of the right had side
          of a map or abbreviation. Please point me to the variants.

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Benjamin R. Haskell
          ... Those are the variants. ... Means that a would turn into bcd , which then gets remapped, turning into efcd . ... Means that a would turn into bcd ,
          Message 4 of 7 , Feb 4, 2012
          • 0 Attachment
            On Sat, 4 Feb 2012, howardb21 wrote:

            > On Feb 2, 10:26 pm, Jürgen Krämer <jottka...@...> wrote:
            >> Hi,
            >>
            >> There are also [ic]noreabbrev variants which would prevent the
            >> right-hand-side of an abbreviation to be re-used as the
            >> left-hand-side of a mapping.
            >
            > Where do I find these variants? I searched Vim's documentation and
            > only found versions of nore that prevent re-use of the right had side
            > of a map or abbreviation. Please point me to the variants.

            Those are the variants.

            :nmap a bcd
            :nmap b ef

            Means that 'a' would turn into 'bcd', which then gets remapped, turning
            into 'efcd'.

            :nnoremap a bcd
            :nnoremap b ef

            Means that 'a' would turn into 'bcd', but it stays 'bcd' because of the
            no-re-mapping.

            --
            Best,
            Ben

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Jürgen Krämer
            Hi, ... Regards, Jürgen -- Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact
            Message 5 of 7 , Feb 5, 2012
            • 0 Attachment
              Hi,

              howardb21 wrote:
              > On Feb 2, 10:26 pm, Jürgen Krämer <jottka...@...> wrote:
              >>
              >> There are also [ic]noreabbrev variants which would prevent the
              >> right-hand-side of an abbreviation to be re-used as the left-hand-side
              >> of a mapping.
              >
              > Where do I find these variants? I searched Vim's documentation and
              > only found versions of nore that prevent re-use of the right had side
              > of a map or abbreviation. Please point me to the variants.

              :help :cnoreabbrev
              :help :inoreabbrev

              Regards,
              Jürgen

              --
              Sometimes I think the surest sign that intelligent life exists elsewhere
              in the universe is that none of it has tried to contact us. (Calvin)

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • howardb21
              ... Pardon my ignorance, but the variants of noremap o noeabbrev, simply prevent the the second member of a map/abbreviation from being used as a first member
              Message 6 of 7 , Feb 11, 2012
              • 0 Attachment
                On Feb 5, 11:35 pm, Jürgen Krämer <jottka...@...> wrote:
                > Hi,
                >
                > howardb21 wrote:
                > > On Feb 2, 10:26 pm, J rgen Kr mer <jottka...@...> wrote:
                >
                > >> There are also [ic]noreabbrev variants which would prevent the
                > >> right-hand-side of an abbreviation to be re-used as the left-hand-side
                > >> of a mapping.
                >
                > > Where do I find these variants?

                >   :help :cnoreabbrev
                >   :help :inoreabbrev
                >
                > Regards,
                > J rgen

                Pardon my ignorance, but the variants of noremap o noeabbrev, simply
                prevent the
                the second member of a map/abbreviation from being used as a first
                member in another map/abrev. OR they restrict a mapping/abrev to one
                mode only.

                If I go :inoreabbrev g group

                this prevents group from being
                used as an abbreviation, and prevents, `g' from being expanded on the
                command line. but it does not prevent `g' from being used in Another
                map or abbreviation anywhere. It g is used for another insert mode
                abbreviation - not too bad - last definition will win. If it it done
                in command or normal mode, than g will
                act differently in insert, normal, command, even visual modes and
                never, perhaps act as as the original `go' command of normal mode.

                It still seems, there is no way to map or abrev a character in such a
                way that this character is prohibited from being mapped or abrev'ed
                again, unless the original
                map/abrev is undone.

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • Jürgen Krämer
                Hi, ... yes, the leading i and c restrict the abbreviation to insert mode and command-line mode, respectively. The nore part prevents the just expanded
                Message 7 of 7 , Feb 13, 2012
                • 0 Attachment
                  Hi,

                  howardb21 wrote:
                  >
                  > On Feb 5, 11:35 pm, Jürgen Krämer <jottka...@...> wrote:
                  >> Hi,
                  >>
                  >> howardb21 wrote:
                  >>> On Feb 2, 10:26 pm, J rgen Kr mer <jottka...@...> wrote:
                  >>
                  >>>> There are also [ic]noreabbrev variants which would prevent the
                  >>>> right-hand-side of an abbreviation to be re-used as the left-hand-side
                  >>>> of a mapping.
                  >>
                  >>> Where do I find these variants?
                  >
                  >> :help :cnoreabbrev
                  >> :help :inoreabbrev
                  >>
                  >> Regards,
                  >> J rgen
                  >
                  > Pardon my ignorance, but the variants of noremap o noeabbrev, simply
                  > prevent the
                  > the second member of a map/abbreviation from being used as a first
                  > member in another map/abrev. OR they restrict a mapping/abrev to one
                  > mode only.
                  >
                  > If I go :inoreabbrev g group
                  >
                  > this prevents group from being
                  > used as an abbreviation, and prevents, `g' from being expanded on the
                  > command line.

                  yes, the leading "i" and "c" restrict the abbreviation to insert mode
                  and command-line mode, respectively. The "nore" part prevents the just
                  expanded right-hand-side ("group" in your case) from being immediately
                  used as the left-hand-side of a map. E.g., if you had defined

                  :iabbrev g group
                  :imap group <c-o>:echo "This is my group."<cr>

                  and you enter "g" and a space in insert mode, only the space would be
                  inserted into the buffer and the text "This is my group." would be
                  echoed on the command line.

                  > but it does not prevent `g' from being used in Another
                  > map or abbreviation anywhere. It g is used for another insert mode
                  > abbreviation - not too bad - last definition will win. If it it done
                  > in command or normal mode, than g will
                  > act differently in insert, normal, command, even visual modes and
                  > never, perhaps act as as the original `go' command of normal mode.
                  >
                  > It still seems, there is no way to map or abrev a character in such a
                  > way that this character is prohibited from being mapped or abrev'ed
                  > again, unless the original
                  > map/abrev is undone.

                  There is the <unique> flag for maps and abbreviations (see

                  :help :map-<unique>

                  ), which prevents you from redefining/overwriting a map or abbreviation,
                  though it seems a map can still be overwritten by an abbreviation and
                  vice versa.

                  Regards,
                  Jürgen

                  --
                  Sometimes I think the surest sign that intelligent life exists elsewhere
                  in the universe is that none of it has tried to contact us. (Calvin)

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                Your message has been successfully submitted and would be delivered to recipients shortly.