Vim Commands

Vim commands are notoriously arcane and weird, but quick once you learn them.

All commands must be done in "Normal" mode, accessed by pressing esc if in write mode. Commands are case sensitive and must be confirmed with Enter unless otherwise noted. <c-x> means Ctrl+x.

Many of these commands derive from the original Unix text line editor ed. If you don't understand why things are the way they are here, pulling the thread of ed may benefit your understanding.


Description Command
Quit :q
Quit and do not save :cq
Save and quit ZZ
Save :w
Save and quit :wq
Save only if file changed and quit :x
Save As :w newFileName
Open for editing :e path/to/file
Open for reading/viewing :v path/to/file
Open file under cursor gf
Go to next file in buffer :bn
Go to previous file in buffer :bN
See all files in buffer :ls or :buffers


Description Command
Undo u
Undo all changes to a line U
Redo <c-r>


Description Command Notes
Find next or previous pattern /pattern or ?pattern Go to next occurrence with n and previous with N
Find and replace from line m to line n :[m],[n]s/pattern/repl[/options] To replace all, add g option; for confirmation, use c option
Find and replace in whole file :%s/pattern/repl Same options apply as above


Description Command
Move cursor (Left, Down, Up, Right) h, j, k, l
See current cursor location and information <c-g>
Go to start/end of next word w/e
Go back a word b
Go to next instance of character a f[a]
Go to previous instance of character a F[a]
Go to character before next instance of character a t[a]
Go to character before previous instance of character a T[a]
Repeat last f/F/t/T in same direction ;
Repeat last f/F/t/T in opposite direction ,
Go to start/end of line 0/$
Go to linen [n]G or [n]gg
Go to beginning of file gg
Go to end of file G
Go to beginning of line 0
Go to first non-space character of line ^
Go to end of line $
Go to matching bracket under cursor; e.g. ( goes to ) and vice versa; includes []{} %
Go to next enclosing brace ]}
Go to previous enclosing brace [{
Go to next page <c-f>
Go to next half page <c-d>
Go to previous page <c-b>
Go to previous half page <c-u>

Copy (Yank), Cut, and Paste

Copy is "yank" in Vim, so that's why they are "y".

Description Command
Copy entire line or n lines, including newline [n]Y
Copy from cursor to end of line y$
Copy from cursor to first non-space character on the line y^
Copy from cursor to start of line y0
Cut entire line or n lines, including newline [n]dd
Cut from cursor to end of line d$
Cut from cursor to first non-space character on the line d^
Cut from cursor to start of line d0
Paste before the cursor P
Paste after the cursor p
Move line up one line ddkP
Move line down one line ddp


Description Command
Delete entire line or n lines, including newline [n]dd
Delete from current column to end of line D
Delete whitespace from cursor until first non-whitespace character dw
Delete contents from cursor to end of n words and enter Insert mode c[n]e or c[n]w
Delete contents from cursor to end of n lines and enter Insert mode [n]C
Delete character under cursor and enter Insert mode s
Delete entire line and enter Insert mode S
Delete contents of n lines and enter Insert mode c[n]c
Replace letter under cursor with letter l r[l]
Enter replace mode (like overwrite) R

Text Manipulation

Description Command Notes
Insert mode i
Enter Insert mode at the beginning of the line I
Append after current character/at end of line a/A
Make a new line above/below current line and enter insert mode O/o
Insert (or retrieve) contents of FILENAME at cursor :r FILENAME
Insert (or retrieve) return of shell command at cursor :r !command
Insert on multiple lines[15] <c-v>, select area, I, do edits, esc
Indent line(s) in command mode << or >>
Indent line in insert mode <c-d> or <c-t>
Append to multiple lines[14] V, select lines, :'<,'>s/$/text/ '<,'> will get added to your command automatically after :
Join line below current line with current line[17] J
Flip capitalization ~
Autocomplete whole line from file <c-x><c-l>
Autocomplete keyword from file <c-x><c-n>
Autocomplete definition from file <c-x><c-d>
Autocomplete filename from file <c-x><c-f>


Mode Command
Insert i
Replace (overwrite) R
Visual (selection using the cursor) v
Visual line (selection of lines) V
Visual block (selection of columns/lines) <c-v>
Exit current mode ESC


A register is any key ([a-zA-Z0-9]).

Description Command
Start recording under register n qn
Stop recording q
Replay recorded keystrokes @n
Replay last macro @@

Split Screen

Description Command
Split current file horizontally <c-w> s
Split current file vertically <c-w> v
Navigate to different panes <c-w> {direction}
Increase/decrease pane width <c-w> >, <c-w> <
Increase/decrease pane height <c-w> +, <c-w> -
Equalize pane height/width <c-w> =
Close a pane <c-w> q


Description Command
Toggle fold at next logical break za
Execute shell command x :!x
Execute last edit again at cursor .
Suspend Vim and go to shell <c-z>
Return to suspended Vim instance fg



Last modified: 202206112135