Command Line

Vim Commands Cheat Sheet

Vim is a text editor that runs on the command line. Using Vim you will navigate around the screen with the keyboard instead of a mouse. It has a steep learning curve, but it can greatly improve your productivity once you master it.

Vim Commands Cheat Sheet thumbnail

Vim is a powerful and popular text editor that runs on the command line. Using Vim, you navigate around on screen with a keyboard instead of a mouse. It has a steep learning curve, but it can greatly improve your productivity once you master it.

Here are some basic Vim commands to help you get started.

Frequently Used Commands

CommandWhat It Does
iInsert before the cursor.
EscExit insert mode.
: numberShow line number.
/patternSearch for pattern.
nRepeat search in same direction.
$Move cursor to end of line.
GGMove cursor to bottom of page.
ggMove cursor to the top of page.
yyYank, or copy, a line.
pPaste the clipboard after the cursor.
:qQuit. This fails if there are unsaved changes.
:wq, :x, ZZWrite, or save, and quit.
:wWrite, or save, the file, but do not exit.

Commands To Move The Cursor

CommandWhat It Does
hMove cursor left.
jMove cursor down.
kMove cursor up.
lMove cursor right.
gjMove cursor down in multi-line text.
gkMove cursor up in multi-line text.
HMove to top of screen.
MMove to middle of screen.
LMove to bottom of screen.
wJump forwards to the start of a word.
WJump forwards to the start of a word. Words can contain punctuation.
eJump forwards to the end of a word.
EJump forwards to the end of a word. Words can contain punctuation.
bJump backwards to the start of a word.
BJump backwards to the start of a word. Words can contain punctuation.

Commands For Editing

CommandWhat It Does
rReplace a single character.
RReplace more than one character until Esc is pressed.
JJoin the line below to the current one with one space in between.
gJJoin the line below to the current one without a space in between.
ccChange, or replace, the entire line.
c$, CChange, or replace, to the end of the line.
ciwChange, or replace, the entire word.
cw, ceChange, or replace, to the end of the word.
sDelete character and substitute text.
SDelete line and substitute text. Same as cc.
xpTranspose two letters by deleting and pasting.
uUndo.
URestore, or undo, the last changed line.
Ctrl + rRedo.
.Repeat last command.

Commands For Saving And Exiting

CommandWhat It Does
:wWrite, or save, the file, but do not exit.
:w !sudo tee %Write out the current file using sudo.
:wq, :x, ZZWrite, or save, and quit.
:qQuit. This fails if there are unsaved changes.
:q!, ZQQuit and throw away unsaved changes.
:wqaWrite, or save, and quit on all tabs.

Command For Search And Replace

CommandWhat It Does
/patternSearch for pattern.
?patternSearch backward for pattern.
nRepeat search in same direction.
NRepeat search in opposite direction.

Commands For Cut And Paste

CommandWhat It Does
yyYank, or copy, a line.
2yyYank, or copy, two lines.
ywYank, or copy, the characters of the word from the cursor position to the start of the next word.
yiwYank, or copy, the word under the cursor.
y$, YYank, or copy, to the end of the line.
pPut, or paste, the clipboard after cursor.
PPut, or paste, before cursor.
ddDelete, or cut, a line.

Visual Commands

CommandWhat It Does
>Shift text right.
<Shift text left.
yYank, or copy, marked text.
dDelete marked text.
~Switch case.
uChange marked text to lowercase.
UChange marked text to uppercase.
Vim Commands Cheat Sheet | SuperSQA