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

keymaps vs. :lnoremap's

Expand Messages
  • Benji Fisher
    According to :help keymap-file-format, These items are exactly the same as what can be used in a |:lnoremap| command. You can check the result with this
    Message 1 of 3 , Apr 1, 2003
      According to :help keymap-file-format,

      These items are exactly the same as what can be used in a |:lnoremap| command.
      You can check the result with this command: >
      :lmap
      [snip]
      Since the mapping is defined with |:lnoremap| ...

      so I thought that keymaps would behave the same as :lnoremap's but I seem to
      have found a difference. If I try

      :lnoremap a A
      :inoremap a foo

      (in that order!) then "a" expands to "foo" whether or not 'iminsert' is set.
      However, when I try

      :set keymap=short
      :inoremap a foo

      (where I have ~/.vim/keymap/short.vim as in the example under
      :help keymap-file-format) then "a" expands to "A" when 'iminsert' is active.

      Is this behavior intended? Is there a work-around? Unless I am missing
      something, there is no way to use :imap's along with keymaps.

      --Benji Fisher
    • Bram Moolenaar
      ... The language mappings are added as buffer-local mappings. These overrule global mappings. Thus you get the same behavior when using ... -- ### Hiroshima
      Message 2 of 3 , Apr 1, 2003
        Benji Fisher wrote:

        > According to :help keymap-file-format,
        >
        > These items are exactly the same as what can be used in a |:lnoremap| command.
        > You can check the result with this command: >
        > :lmap
        > [snip]
        > Since the mapping is defined with |:lnoremap| ...
        >
        > so I thought that keymaps would behave the same as :lnoremap's but I seem to
        > have found a difference. If I try
        >
        > :lnoremap a A
        > :inoremap a foo
        >
        > (in that order!) then "a" expands to "foo" whether or not 'iminsert' is set.
        > However, when I try
        >
        > :set keymap=short
        > :inoremap a foo
        >
        > (where I have ~/.vim/keymap/short.vim as in the example under
        > :help keymap-file-format) then "a" expands to "A" when 'iminsert' is active.
        >
        > Is this behavior intended? Is there a work-around? Unless I am
        > missing something, there is no way to use :imap's along with keymaps.

        The language mappings are added as buffer-local mappings. These
        overrule global mappings. Thus you get the same behavior when using

        :lnoremap <buffer> a A

        You can then overrule the mapping with:

        :inoremap <buffer> a foo

        --
        ### Hiroshima 45, Chernobyl 86, Windows 95 ###

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
      • Benji Fisher
        Bram Moolenaar wrote: [snip] ... Thanks, that does it. I should have looked more closely at the output of ... (I know the * for the nore variant, but I
        Message 3 of 3 , Apr 1, 2003
          Bram Moolenaar wrote:
          [snip]
          >
          > The language mappings are added as buffer-local mappings. These
          > overrule global mappings. Thus you get the same behavior when using
          >
          > :lnoremap <buffer> a A
          >
          > You can then overrule the mapping with:
          >
          > :inoremap <buffer> a foo

          Thanks, that does it. I should have looked more closely at the output of

          :lmap

          (I know the * for the "nore" variant, but I still have to get used to @ for
          buffer-local. Can I blame my head cold?)

          I now have

          :inoremap <buffer> a a<Esc>:call MyFun()<CR>

          and, before doing other stuff, MyFun() checks maparg("a", "l") and replaces the
          "a" with the keymap value if defined (and if 'iminsert' is set).

          --Benji Fisher
        Your message has been successfully submitted and would be delivered to recipients shortly.