Vim Cheat Sheet, The Complete Beginners Guide for Vim
Vim is a popular and powerful text editor that has been around for several decades. It’s a command-line-based editor, which means it runs in a terminal or console window rather than having a graphical user interface like most modern text editors. Vim offers a range of features that make it a favorite among many programmers, writers, and power users.
2 min readJun 13, 2023
MOVEMENT
h or ← #===> Move cursor left.
j or ↓ #===> Move cursor down.
k or ↑ #===> Move cursor up.
l or → #===> Move cursor right.
w #===> Move to the beginning of the next word.
b #===> Move to the beginning of the previous word.
e #===> Move to the end of the current word.
0 #===> Move to the beginning of the current line.
$ #===> Move to the end of the current line.
gg #===> Move to the first line of the document.
G #===> Move to the last line of the document.
Ctrl + F #===> Move forward one page.
Ctrl + B #===> Move backward one page.
EDITING
i #===> Insert text before the cursor.
a #===> Append text after the cursor.
o #===> Insert a new line below the current line.
O #===> Insert a new line above the current line.
x #===> Delete the character under the cursor.
dd #===> Delete the current line.
yy #===> Copy the current line.
p #===> Paste the copied or deleted text below the current line.
P #===> Paste the copied or deleted text above the current line.
u #===> Undo the last change.
Ctrl + R #===> Redo the last change.
. #===> Repeat the last command.
SEARCH AND REPLACE
/pattern. #===> Search forward for the specified pattern
?pattern. #===> Search backward for the specified pattern
n #===> Jump to the next occurrence of the search pattern
N #===> Jump to the previous occurrence of the search pattern
:%s/old/new/g #===> Replace occurrences of "old" with "new" in the entire file
:s/old/new/g #===> Replace occurrences of "old" with "new" in the current line
:s/old/new/gc #===> Replace occurrences of "old" with "new" in the current line with confirmation
SAVING AND QUITTING
:w #===> Save the file
:q #===> Quit Vim
:wq or :x #===> Save and quit Vim
:q! #===> Quit Vim without saving changes
VISUAL MODE
v #===> Enter character-wise visual mode
V #===> Enter line-wise visual mode
Ctrl + V #===> Enter block-wise visual mode
# Use movement commands to select text, then perform operations like deletion or copy/paste