I know you can add custom keymappings to vim with imap in the .vimrc file. My question is, if one is to create additional custom operators, motions, commands and map them to keys, what is the best way to add them in so they don’t conflict with existing bindings?
An analogy, in emacs, a lot of custom key commands are added via the C-c sequence. To be more technical, are there unbound keys in vim that allow for user customization? In other words, is there a free keyspace available to users?
:imapEnter will show a list of your insert mode mappings.In my opinion the best way is creating custom command, they start with uppercase, native ones with lowercase.
Additionally, you can use a
<leader>I use , some use \.e.g.
:let mapleader = ","then, you can use the leader to combine it with other keys, like ,p to call a command, native or custom, see below:
:map <leader>p :MyCustomCommand<CR>A custom motion example. Delete the third word after the cursor.
nnoremap <leader>x :normal 2wdw<CR>Several commands can be used to create new, remove and list the mappings, here is a list of working modes, from
:help map-overviewfurther info
:help mapHere’s an example function, converted to a custom command
Now, both lines below are equivalent
:call MoveLastLines('newFile.txt'):MoveTo newFile.txt