So far I've been trying to use Vim in as vanilla a configuration as possible, so as to save myself hassle when moving between machines. However, there are a few things I'd really like to bind keys, such as to shorten "_diwP which I use often to delete the word under the cursor and replace it with one from the clipboard. Are there any particular keys that are conventionally reserved for user-defined mappings? The point of this question is mostly that I would like to avoid hassle later on when I decide to install some plugin or take my configuration files to vim on another OS and find that my key mappings clash with something else.
- 243
4 Answers
All the letters are already taken – see :help index.
But if I want permanent commands I use <leader> as a prefix.
:map <leader>l :list!
The default leader is '' so by typing \l I can switch the state of list.
Note the leader can be changed. See :help leader
Note: to make sure I have my vim mapping available anytime I want them, I just put the .vimrc file on a convenient webserver. Then I can just use wget (or a browser) to get my .vimrc file at any time.
- 3
- 3
- 11,190
All keys are safe to remap in Vim. However, there are two types of mappings: recursive and non recursive.
a) Recursive:
If you remap for example,
nmap x dd
x deletes the line instead of one character
you will have effectively lost the x key for future mappings, as well as overwritten the delete character function. Were sometime in the future some plugin depend on that key, that could present a problem.
For example,
nmap <C-x> xxx
will delete three lines instead of three characters, because it is effectively doing dddddd. This is a problem since effectively were some of your plugins to use the x (and they surely will) it will create problems (nasty ones).
b) Non recursive mapping
nnoremap x dd
solves that problem in a way that it will assign dd to x so that upon your pressing x you delete a line instead of a character, but any future mapping
nnoremap <C-x> xxx
will have the original x on the right hand side functionality.
Always use nnoremap, inoremap ... the non-recursive mapping instead of nmap, imap and so on ... unless you have a very strong reason for doing the opposite.
- 19,947
If you have the Alt Gr key, its REALLY useful for situations like this, since if you press it in combination with other letters you have a whole new alphabet available.
I use:
- Alt Gr + s (ß), for easyMotion search for letter;
- Alt Gr + y (←) to yank into the register q;
- Alt Gr + p (þ) to paste the content of the register q;
- and so on..
- 111