This is a small collection of tips and tricks I have collected for the vim text editor. This is by no means complete or a tutorial on how to use vim. Just a set of commands I don’t want to forget, but don’t use often enough to burn into memory, yet.
See the resources section below for a more complete introduction and a set of in-depth tutorials.
ma “ mark spot label it a ‘a “ jump to spot “ ” jump to last spot you were
Vim has a clipboard history stored in registers, you can also use these registers to cut and paste items to.
"ad " cut something to register a
"ap " paste something from register a
:reg " list registers
:g/regexp/d " delete all lines that match regexp
:v/regexp/d " delete all lines that do NOT regexp
:15,20d " delete lines 10-20
:ls " matching list buffers
:b [num|name] " switch to buffer
:b# " switch to last buffer
:bdel # " delete buffer
qa " start recording macro in buffer a
<do stuff>
q " end recording
@a
50@a (50 times)
Map ctrl-j d to run system command /tmp/x.py
:imap <c-j>d <c-r>=system('/tmp/x.py')<cr>
:map <F5> :setlocal spell! spelllang=en_us<CR>
I often find myself trying to hit escape and accidentally hit F1, which opens help. Since, I’ve never on purpose hit F1 for help, I map my F1 key to ESC.
map <F1> <Esc>
imap <F1> <Esc>