Re: keymaps vs. :lnoremap's
- Benji Fisher wrote:
> According to :help keymap-file-format,The language mappings are added as buffer-local mappings. These
> These items are exactly the same as what can be used in a |:lnoremap| command.
> You can check the result with this command: >
> 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.
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 ///
- Bram Moolenaar wrote:
>Thanks, that does it. I should have looked more closely at the output of
> 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
(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).