Skip to main content

Vim Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for Vim text editor commands

Vim is a powerful modal text editor that comes pre-installed on most Linux systems. This cheatsheet covers essential commands for navigating, editing, searching, and managing files in Vim. Master these commands to dramatically increase your editing speed.

Modes

Switch between Vim’s different editing modes.

CommandDescription
iInsert mode (before cursor)
IInsert at line beginning
aInsert mode (after cursor)
AInsert at line end
oNew line below
ONew line above
EscReturn to Normal mode
vVisual mode
VVisual line mode
Ctrl+vVisual block mode

Save & Quit

Save files and exit the editor.

CommandDescription
:wSave file
:w filenameSave as filename
:qQuit
:q!Quit without saving
:wqSave and quit
:xSave and quit
ZZSave and quit
ZQQuit without saving

Move around the file efficiently.

CommandDescription
hMove left
jMove down
kMove up
lMove right
wNext word
bPrevious word
eEnd of word
0Line beginning
$Line end
^First non-blank char

Jump Around

Navigate to specific locations quickly.

CommandDescription
ggGo to first line
GGo to last line
5GGo to line 5
:5Go to line 5
Ctrl+fPage down
Ctrl+bPage up
Ctrl+dHalf page down
Ctrl+uHalf page up
%Jump to matching bracket
HTop of screen
MMiddle of screen
LBottom of screen

Delete

Remove text from the file.

CommandDescription
xDelete character
XDelete char before cursor
ddDelete line
DDelete to line end
dwDelete word
d$Delete to line end
d0Delete to line start
dGDelete to file end
dggDelete to file start
5ddDelete 5 lines

Copy & Paste

Yank (copy) and put (paste) text.

CommandDescription
yyYank (copy) line
ywYank word
y$Yank to line end
5yyYank 5 lines
pPaste after cursor
PPaste before cursor
"*yYank to system clipboard
"*pPaste from clipboard
"+yYank to clipboard (X11)
"+pPaste from clipboard (X11)

Undo & Redo

Reverse and repeat changes.

CommandDescription
uUndo
UUndo line changes
Ctrl+rRedo
.Repeat last command

Find text in the file.

CommandDescription
/patternSearch forward
?patternSearch backward
nNext match
NPrevious match
*Search word under cursor
#Search backward for word
:nohClear search highlight

Find & Replace

Search and replace text patterns.

CommandDescription
:s/old/new/Replace first on line
:s/old/new/gReplace all on line
:%s/old/new/gReplace all in file
:%s/old/new/gcReplace with confirm
:5,10s/old/new/gReplace in lines 5-10

Visual Mode

Select and manipulate text blocks.

CommandDescription
vStart visual mode
VSelect lines
Ctrl+vSelect block
yYank selection
dDelete selection
>Indent selection
<Unindent selection
~Toggle case
uLowercase
UUppercase

Indentation

Adjust text indentation.

CommandDescription
>>Indent line
<<Unindent line
5>>Indent 5 lines
=Auto-indent
gg=GAuto-indent entire file
:set tabstop=4Set tab width
:set expandtabUse spaces for tabs

Line Numbers

Display and navigate with line numbers.

CommandDescription
:set numberShow line numbers
:set nuShow line numbers
:set nonumberHide line numbers
:set relativenumberRelative line numbers
:set rnuRelative line numbers

Multiple Files

Work with multiple files and buffers.

CommandDescription
:e filenameOpen file
:bnNext buffer
:bpPrevious buffer
:bdClose buffer
:lsList buffers
:sp filenameHorizontal split
:vsp filenameVertical split
Ctrl+w wSwitch window
Ctrl+w qClose window
:tabnewNew tab
gtNext tab
gTPrevious tab

Marks

Set and jump to bookmarks.

CommandDescription
maSet mark ‘a’
'aJump to mark ‘a’
`aJump to exact position
:marksList all marks
''Jump to last position
`.Jump to last edit

Macros

Record and replay command sequences.

CommandDescription
qaStart recording to ‘a’
qStop recording
@aPlay macro ‘a’
@@Replay last macro
5@aPlay macro 5 times

Settings

Configure Vim behavior.

CommandDescription
:set ignorecaseCase insensitive search
:set smartcaseSmart case search
:set hlsearchHighlight search
:set incsearchIncremental search
:set wrapWrap long lines
:set nowrapDisable line wrapping
:syntax onEnable syntax colors
:set pastePaste mode (no indent)