VIM Keyboard Shortcuts Cheatsheet

Vim Cheatsheet 00 Featured Image

Vim is a powerful command-line code editor tool that’s an enhanced version of the venerable vi editor. Although most people use it with Linux, Vim is compatible with most of the commonly used operating systems, including macOS, Windows, and DOS.

Despite the abundance of graphical rich text editors, familiarity with Vim will help every user, from an experienced system administrator to a newbie programming a Raspberry Pi. However, one important thing to note when using Vim, is that the function of a key depends on the “mode” the editor is in. For example, pressing the alphabet “j” will move the cursor down one line in the “command mode”. You’ll have to switch to the “insert mode” to make the keys input the character they represent.

If you’re new to Vim, open a terminal and run vimtutor to get you started with some initial commands before diving into the rest.

VIM Keyboard Shortcuts Cheatsheet Download

Download this Cheatsheet

Enter your email below to receive this PDF cheatsheet in your Inbox.

Here’s a cheatsheet to help you get the most out of Vim.

Shortcut KeysFunction
Main
EscGets out of the current mode into the “command mode”. All keys are bound of commands.
I“Insert mode” for inserting text. Keys behave as expected.
:“Last-line mode” where Vim expects you to enter a command such as to save the document.
:termOpen a terminal window.
Navigation Keys
HMove the cursor one character to the left.
J or Ctrl + JMove the cursor down one line.
K or Ctrl + PMove the cursor up one line.
lMove the cursor one character to the right.
0Move the cursor to the beginning of the line.
$Move the cursor to the end of the line.
^Move the cursor to the first non-empty character of the line.
wMove forward one word (next alphanumeric word).
WMove forward one word (delimited by a white space).
5WMove forward five words.
bMove backward one word (previous alphanumeric word).
BMove backward one word (delimited by a white space).
5BMove backward five words.
GMove to the end of the file.
GGMove to the beginning of the file.
Navigate Around The Document
(Jump to the previous sentence.
)Jump to the next sentence.
{Jumps to the previous paragraph.
}Jumps to the next paragraph.
[[Jumps to the previous section.
]]Jumps to the next section.
[]Jump to the end of the previous section.
][Jump to the end of the next section.
Insert Text
a
(lowercase A)
Insert text after the cursor.
A
(uppercase A)
Insert text at the end of the line.
IInsert text before the cursor.
o
(lowercase O)
Begin a new line below the cursor.
O
(uppercase A)
Begin a new line above the cursor.
Special Inserts
:R [filename]Insert the file [filename] below the cursor.
:R ![command]Execute [command] and insert its output below the cursor.
Delete Text
XDelete character at cursor.
DWDelete a word.
D0Delete to the beginning of a line.
D$Delete to the end of a line.
D)Delete to the end of sentence.
DGGDelete to the beginning of the file.
DGDelete to the end of the file.
DDDelete line.
3DDDelete three lines.
Simple Replace Text
R{text}Replace the character under the cursor with {text}.
RReplace characters instead of inserting them.
Copy/Paste Text
YYCopy current line into storage buffer.
[“x]yyCopy the current lines into register x.
p
(lowercase P)
Paste storage buffer after current line.
P
(uppercase A)
Paste storage buffer before current line.
[“X]PPaste from register x after current line.
[“X]PPaste from register x before current line.
Text Modification
CCChange the text of the current line.
CEChange the currently selected word at the current cursor point.
C$Change the text from the cursor position until the end of the line.
C0Change the text from the cursor position until the start of the line.
G~Switch the case of the currently selected text as well as the line adjacent to it to its opposite.
GuChange the case of the currently selected text as well as the line adjacent to it to lowercase.
GUChange the case of the currently selected text as well as the line adjacent to it to uppercase.
Context-Specific Modification
CIWChange the currently selected word regardless of cursor position.
CIPChange the currently selected paragraph or code block regardless of cursor position.
CI<Change the content of a code block enclosed in angle brackets (<>).
CI{Change the content of a code block enclosed in curly brackets ({}).
DIWDelete the currently selected word regardless of cursor position.
DIPDelete the currently selected paragraph or code block regardless of cursor position.
DAWDelete the currently selected word as well as the spaces before and after it.
DI<Delete the content of a code block enclosed in angle brackets (<>).
DI{Delete the content of a code block enclosed in curly brackets ({}).
YIWCopy the currently selected word regardless of cursor position.
YIPCopy the currently selected paragraph or code block regardless of cursor position.
YAWCopy the currently selected word as well as the spaces before and after it.
YI<Copy the content of a code block enclosed in angle brackets (<>).
YI{Copy the content of a code block enclosed in curly brackets ({}).
Undo/Redo Operation
UUndo the last operation.
Ctrl + RRedo the last undo.
:earlier 1mGo back 1 minute in the history of the document.
:later 1mGo forward 1 minute in the history of the document.
Search and Replace Keys
/search_textSearch document for search_text going forward.
?search_textSearch document for search_text going backward.
n
(lowercase n)
Move to the next instance of the result from the search.
N
(uppercase A)
Move to the previous instance of the result.
:%s/original/replacementSearch for the first occurrence of the string “original” and replace it with “replacement”.
:%s/original/replacement/gSearch and replace all occurrences of the string “original” with “replacement”.
:%s/original/replacement/gcSearch for all occurrences of the string “original” but ask for confirmation before replacing them with “replacement”.
FSearch for the next occurrence of a character or go to the previous occurrence.
Bookmarks
M {a-z A-Z}Set bookmark {a-z A-Z} at the current cursor position.
:marksList all bookmarks.
`{a-z A-Z}Jumps to the bookmark {a-z A-Z}.
Select Text
v
(lowercase V)
Enter visual mode per character.
V
(uppercase A)
Enter visual mode per line.
EscExit visual mode.
Modify Selected Text
~Switch case.
DDelete a word.
CChange a word.
YYank (copy) a word.
>Shift right.
<Shift left.
!Filter through an external command.
Text Indentation
>>Shift the currently selected line one Tab length to the right.
<<Shift the currently selected line one Tab length to the left.
gg=GShift the current buffer by one Tab length.
>%Shift the currently selected code block to the right.
<%Shift the currently selected code block to the left.
>IBShift the contents of the currently selected block to the right.
<IBShift the contents of the currently selected block to the left.
>ATShift the contents of a block that is enclosed in angle brackets (<>) to the right.
<ATShift the contents of a block that is enclosed in angle brackets (<>) to the left.
Macros
Q[character]Record a Vim macro that is accessible under the [character] key.
QStop a Vim macro recording.
@[character]Execute a recorded Vim macro that was saved under the [character] key.
@@Execute the last Vim macro that was run.
Search and Execute
:G/[pattern]/[vim command]Run the [vim command] in the current line for every instance of the [pattern].
:G!/[pattern]/[vim command]Run the [vim command] in the current line for every instance that is not the [pattern].
:%G/[pattern]/[vim command]Run the [vim command] on the entire document for every instance of the [pattern].
:%G!/[pattern]/[vim command]Run the [vim command] on the entire document for every instance that is not the [pattern].
Tab Manipulation
:TABE [file path]Open the [file path] in a separate tab in the current buffer.
:TABNSwitch to the next active tab in the buffer.
:TABPSwitch to the previous active tab in the buffer.
:TABCClose the currently active tab in the buffer.
:TABOClose all inactive tabs in the buffer.
Buffer Manipulation
:SP [file path]Open the [file path] as a horizontally split buffer.
:VSP [file path]Open the [file path] as a vertically split buffer.
:LSShow a list of all the buffers currently open in Vim.
:BNDisplay the contents of the next open buffer in the buffer list.
:BPDisplay the contents of the previous open buffer in the buffer list.
Ctrl + W, then SSplit the current window horizontally, displaying the currently active buffer in both windows.
Ctrl + W, then VSplit the current window vertically, displaying the currently active buffer in both windows.
Ctrl + W, then WSwitch focus between the split buffers.
Ctrl + W, then XSwap the position of the currently focused buffer with an inactive one.
Ctrl + W, then QDelete the currently selected buffer.
Save and Quit
:QQuits Vim but fails when file has been changed.
:WSave the file.
:W new_nameSave the file with the new_name filename.
:WQSave the file and quit Vim.
:Q!Quit Vim without saving the changes to the file.
ZZWrite file, if modified, and quit Vim.
ZQSame as :q! Quits Vim without writing changes.
:sav file
:saveas file
Save file as.
:clo
:close
Close the current pane.

Image credit: Unsplash

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red
Ramces Red - Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.