Reputation: 8480
I write a lot of code and tired of pressing shift each time I need a special character. And since I use special chars much often, then numbers, I want to reverse shift behavior on them.
So, if I type <4> I'll get '$' and if I type <shift>+<4> I'll get '4' and so on for each number. This mapping should work only in insert mode.
I've tried:
:set langmap 123...;!@#...,!@#...;123 "works only in normal-mode
:imap 4 $
:imap $ 4 "recursive mapping error
Upvotes: 0
Views: 792
Reputation: 15768
From :help imap
:
If you want to exchange the meaning of two keys you should use the :noremap
command. For example: >
:noremap k j
:noremap j k
This will exchange the cursor up and down commands.
With the normal :map command, when the 'remap' option is on, mapping takes
place until the text is found not to be a part of a {lhs}. For example, if
you use: >
:map x y
:map y x
Vim will replace x with y, and then y with x, etc. When this has happened
'maxmapdepth' times (default 1000), Vim will give the error message
"recursive mapping".
Same applies to imap
(use inoremap
instead).
Upvotes: 0
Reputation: 657
Use :ino
, which does the same thing as :imap
except that it doesn't look for maps in the replaced text. (it's short for 'inoremap') That will fix the recursion issue.
See here for more information: http://vim.dindinx.net/orig/html/map.txt.php
Or type :h map for vim online help (same thing, just inside vim).
Upvotes: 4