In Vim, abbreviations are created with one of the following commands depending on which mode they should be available in:
:iabbrev addr Lincoln Road, Birmingham B27 6PA, United Kingdom
:iabbr teh the
:iabbr forx for(x=0;x<100;x++){<cr><cr>}
:iabbr viml ````VimL<CR><CR>````<CR>
- cabbrev: Abbreviations for the command line only
:cabbr csn colorscheme night
A good place to keep your abbreviations so that you don't have to execute all the commands by hand is in a file in your VIMHOME. Simply place a file there—let's call it abbreviations.vim and write all your abbreviations in it. Then, in your vimrc file, just make sure that the file is read, which is done with the source command:
:source $VIM/abbreviations.vim
The main commands to know when dealing with key bindings are:
- map: For the Normal, Insert, Visual, and Command-line modes
- imap: For the Insert mode only
- cmap: For the Command-line mode only
- nmap: For the Normal mode only
- vmap: For the Visual mode only
Keys |
Notation |
<BS> |
Backspace Tab |
<Tab> |
Tab |
<CR> |
Enter |
<Enter> |
Enter |
<Return> |
Enter |
<Esc> |
Escape |
<Space> |
Space |
<Up> |
Up arrow |
<Down> |
Down arrow |
<Left> |
Left arrow |
<Right> |
Right arrow |
<F1>-F12> |
Function keys 1 to 12 |
#1,2..#9,#0 |
Function keys F1 to F9, F10 |
<Insert> |
Insert |
<Del> |
Delete |
<Home> |
Home |
<End> |
End |
<PageUp> |
Page up |
<PageDown> |
Page down |
Examples:
Saving only when in insert mode:
:imap <C-s> <esc>:w<cr>a
Navigating through buffers
map <C-right> <ESC>:bn<CR>
map <C-left> <ESC>:bp<CR>