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 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
| Command | What It Does |
|---|---|
i | Insert before the cursor. |
Esc | Exit insert mode. |
: number | Show line number. |
/pattern | Search for pattern. |
n | Repeat search in same direction. |
$ | Move cursor to end of line. |
GG | Move cursor to bottom of page. |
gg | Move cursor to the top of page. |
yy | Yank, or copy, a line. |
p | Paste the clipboard after the cursor. |
:q | Quit. This fails if there are unsaved changes. |
:wq, :x, ZZ | Write, or save, and quit. |
:w | Write, or save, the file, but do not exit. |
Commands To Move The Cursor
| Command | What It Does |
|---|---|
h | Move cursor left. |
j | Move cursor down. |
k | Move cursor up. |
l | Move cursor right. |
gj | Move cursor down in multi-line text. |
gk | Move cursor up in multi-line text. |
H | Move to top of screen. |
M | Move to middle of screen. |
L | Move to bottom of screen. |
w | Jump forwards to the start of a word. |
W | Jump forwards to the start of a word. Words can contain punctuation. |
e | Jump forwards to the end of a word. |
E | Jump forwards to the end of a word. Words can contain punctuation. |
b | Jump backwards to the start of a word. |
B | Jump backwards to the start of a word. Words can contain punctuation. |
Commands For Editing
| Command | What It Does |
|---|---|
r | Replace a single character. |
R | Replace more than one character until Esc is pressed. |
J | Join the line below to the current one with one space in between. |
gJ | Join the line below to the current one without a space in between. |
cc | Change, or replace, the entire line. |
c$, C | Change, or replace, to the end of the line. |
ciw | Change, or replace, the entire word. |
cw, ce | Change, or replace, to the end of the word. |
s | Delete character and substitute text. |
S | Delete line and substitute text. Same as cc. |
xp | Transpose two letters by deleting and pasting. |
u | Undo. |
U | Restore, or undo, the last changed line. |
Ctrl + r | Redo. |
. | Repeat last command. |
Commands For Saving And Exiting
| Command | What It Does |
|---|---|
:w | Write, or save, the file, but do not exit. |
:w !sudo tee % | Write out the current file using sudo. |
:wq, :x, ZZ | Write, or save, and quit. |
:q | Quit. This fails if there are unsaved changes. |
:q!, ZQ | Quit and throw away unsaved changes. |
:wqa | Write, or save, and quit on all tabs. |
Command For Search And Replace
| Command | What It Does |
|---|---|
/pattern | Search for pattern. |
?pattern | Search backward for pattern. |
n | Repeat search in same direction. |
N | Repeat search in opposite direction. |
Commands For Cut And Paste
| Command | What It Does |
|---|---|
yy | Yank, or copy, a line. |
2yy | Yank, or copy, two lines. |
yw | Yank, or copy, the characters of the word from the cursor position to the start of the next word. |
yiw | Yank, or copy, the word under the cursor. |
y$, Y | Yank, or copy, to the end of the line. |
p | Put, or paste, the clipboard after cursor. |
P | Put, or paste, before cursor. |
dd | Delete, or cut, a line. |
Visual Commands
| Command | What It Does |
|---|---|
> | Shift text right. |
< | Shift text left. |
y | Yank, or copy, marked text. |
d | Delete marked text. |
~ | Switch case. |
u | Change marked text to lowercase. |
U | Change marked text to uppercase. |
