Vim Cheatsheet
Vim is an editor with a steep learning curve. This is a list of shortcuts that I have learnt and use regularly. It is by no means intended to be a comprehensive list and will continue to grow as I learn more.
File Navigation
h/j/k/l
- left, down, up, rightgg
- to start of fileG
- to end of file0
- to start of line$
- to end of lineb
- to beginning of wordw
- to beginning of next worde
- to end of current or next wordctrl-n
- go down in list, turns out this works on various other software e.g. Chrome + Sublime autocompletectrl-p
- go down in list, turns out this works on various other software like Chrome + Sublime autocompletectrl-d
- move down half a screenctrl-u
- move up half a screenHML
- high, middle, low, move cursor to this position of the screen to prevent hittingkkkkkkkk
.:Ex
- enter netrw
Buffers
:ls
- list all listed buffers:bn
- next buffer:bd
- delete buffer:b
- switch to certain buffer, can tab for autocompletion, can search too. Or use a number from:ls
.
Windows
ctrl-w s
- split horizontally.ctrl-w v
- split vertically.ctrl-w h/j/k/l
- move focus between windowsctrl-w r
- switch windows around (left <-> right)ctrl-w =
- Normalize all split sizes:Vex
- visual split create a new vertical window in netrw mode:Vex!
adds to RHS
Searching
/
- to search. My vimrc settings allow for case-insenstive unless a capital letter is used*
- on a current word to use that as the search termN/n
- Go back and forward between the matches.
Tabs
I don’t use tabs a whole lot, but sometimes I keep a reference file open in a seperate one.
:tabe
- open new tab:tabc
- close tabgt/gT
- next/prev tab
Editing
u
- undoctrl-r
- redop
- pastey
- yank (copy)cib
- change in bracketsyy
- yank linedd
- delete line
Selecting
vib
- select in bracketsV
- select by whole linesv
- select textctrl v
- visual block, when wanting to operate on multiple lines at once (adding tabs, commenting out etc)
Vim Go
gd
- Go to definitionctrl t
- Go back a defintion (pop the ‘go to’ off the stack)
FZF
:FZF
- search for file. Select a file in the list to open in new buffer
Resources
- Graphical cheat sheet - 2006 so dated but looks comprehensive and is often referenced.
- Devhints cheat sheet - this website has a bunch of great software engineering cheatsheets and cuts throught the rubbish.
Settings
You may find my .vimrc settings file here: https://github.com/oliverbenns/dotfiles/blob/master/.vimrc.
Plugins are installed in the setup script of that dotfiles repository.