My VIM basic imap mappings have no effect

3

Good afternoon,

I am struggling with Vim mappings. I would like to practice over very basic ones such as "replace a-s with b-s", or "replace ù with /", but I do not succeed.

Here are my trials:

:imap a b
:imap ù /
:imap 'ù' /
:imap 'ù' '/'

Anytime I get into the insertion mode I have a-s when I press a-s, and ù-s when I press ù-s.
(Besides this I have more complex mappings correctly working, such as nnoremap ,<space> :nohlsearch<CR> or nnoremap <C-H> <C-W><C-H>.)

I am running the following version of Vim:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 17:31:41)

Thanks in advance for your help!

Luc

Posted 2019-10-23T13:38:53.213

Reputation: 33

Answers

1

Your first two forms are correct; there's no quoting involved in mappings. You have to use :help key-notation for certain special keys, though.

If :imap a b does not have any effect in insert mode, something's wrong. My best guess would be that you accidentally have :set paste; this mode is meant for literal pasting and so insert-mode mappings are disabled. You can check with :set paste? and :set nopaste would turn this off (for the current session; you'd need to find out in which file (e.g. .vimrc or a plugin) this was set.

If it's not 'paste', there may be other misconfigurations that cause this. To continue with your (rather simple) experiments, you can start a plain Vim session with vim --clean; this ignores any configuration and then the :imap should definitely work!

Ingo Karkat

Posted 2019-10-23T13:38:53.213

Reputation: 19 513

Thanks… a… lot. I had set paste. Actually I often do so for pasting. Now I will unset it afterwards! Reading the documentation you provided I also see that it solves the abbreviations "not working" ! – Luc – 2019-10-24T09:06:12.890

The 'pastetoggle' option is helpful for quicky changing its value via a key. (You obviously cannot use mappings for that). If you closely observe the lower-left corner, you'll see -- INSERT (paste) -- when this is enabled. If you need a bigger hint, you could also include the paste value in a custom 'statusline'. – Ingo Karkat – 2019-10-24T13:30:14.420