Vim Commands

Movement

ShortcutDescription
hMove left
lMove right
jMove down
kMove up
0Move to beginning of line
$Move to end of line
ggMove to start of the file
GMove to end of the file
wMove to start of next word
eMove to end of next word
bMove to previous word
Ctrl + fMove screen down one page
Ctrl + bMove screen up one page
Ctrl + eMove screen down one line
Ctrl + yMove screen up one line

Editing

ShortcutDescription
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at the end of line
oInsert a new line below the cursor
OInsert a new line above the cursor
xDelete a character
pPaste the deleted line or character
PPaste above the cursor
rxReplace character at current cursor position with x
RReplace mode until Esc is pressed
sDelete the character and enter insert mode
uUndo
UUndo all changes in the current line
Ctrl + rRedo

Operators (Operator [number] motion)

ShortcutDescription
dOperator to delete
cOperator to change words; removes the word and enters insert mode
yOperator to copy lines
d2wDelete two words
y2wCopy two words
c2wDelete two words from cursor and enter insert mode
dwDelete next word
dbDelete previous word
ddDelete whole line
2ddDelete two lines
ceDelete a word and enter insert mode
c$Delete till end of line and enter insert mode
ccRemove whole line and enter insert mode
2wMove cursor two words forward
2bMove cursor two words backward
10jMove cursor down 10 lines
10kMove cursor up 10 lines
35GGo to line 35

Search, Match, Replace

ShortcutDescription
%When cursor is at a parenthesis, go to the matching parenthesis
:s/old/new/gReplace all occurrences of old with new in the current line
:1,20s/old/new/gReplace all occurrences of old with new from lines 1 to 20
:%s/old/new/gReplace all occurrences of old with new in the entire file
:%s/old/new/gcReplace all occurrences of old with new in the entire file, asking for confirmation
Ctrl + gDisplay file status

Execute Shell Commands from Vim

ShortcutDescription
:!lsExecute a shell command by typing ! before the command
:w filenameWrite selected text to a file (select text in Visual mode first)
:r filenameRead file contents into the current file
:r !lsExecute ls and insert its output into the current file
:r !pwdExecute pwd and insert its output into the current file

Editing Multiple Files using Vim Buffers

ShortcutDescription
:e `type the file name or tab to open the file
:badd <filename>Add a new file to the buffer list without switching to it
:ls or :buffersList all open buffers with their assigned numbers
:bn or :bnextSwitch to the next buffer
:bp or :bpreviousSwitch to the previous buffer
:b <number>Jump directly to a specific buffer by its index (e.g., :b 3)
:b! 2If you have modified the file and want to switch to next buffer add ! after the command
:bwremove current buffer
:bw 2delete multiple buffer 2
:bw 2 3 4delete multiple buffers
2 Ctrl + gTo show buffer status

Vim Windows/ View Ports

ShortcutDescription
:split [filename] (or :sp)To open a file in horizontal split and add to buffer
:vsplit [filename] (or :vs)To open a file in vertical split and add to buffer
sb 2Open the existing 2nd file in the buffer in split
vert sb 2Open the 2nd file in the buffer in vertical split
Ctrl + w , arrow keys or hjklTo navigate between split screens
Ctrl + w wTo navigate between all buffers
Ctrl + w rTo reverse the order of windows
Ctrl + w +/-To increase/decrease horizontal split window size
Ctrl + w >/<To increase/decrease vertical split window size
Ctrl + w =To resize the window equally
10 Ctrl + w +,-,>,<To increase/decrease the horizontal/vertical window by 10 lines
:resize [N]Set current split height explicitly to N lines
:vert resize [N]Set current split width explicitly to N columns
closeTo close the split window, but file stays in the buffer
onlyClose everything else except the active split