Vim Cheat Sheet: Essential Commands Every Developer Should Know

If you work with Linux, servers, or programming, Vim is almost impossible to avoid. It’s powerful, fast, and available on nearly every Unix-like system. But the learning curve can feel steep at first.

This Vim cheat sheet gives you the most useful commands in a simple and practical format. You’ll learn how to open files, navigate quickly, edit text efficiently, and save or quit without frustration.


Quick Vim Commands Summary

TaskCommandWhat It Does
Open filevim file.txtOpen a file in Vim
Enter insert modeiStart typing before cursor
Append textaInsert text after cursor
Save file:wWrite changes
Save & quit:wqSave and exit
Quit without saving:q!Exit and discard changes
Delete lineddDelete current line
Copy lineyyCopy current line
PastepPaste after cursor
UndouUndo last action
RedoCtrl + rRedo last undo
Search/wordSearch forward
Replace:%s/old/new/gReplace in entire file
Go to startggJump to first line
Go to endGJump to last line

Opening Files in Vim

The most common way to open a file is:

vim filename.txt

Open multiple files:

vim file1.txt file2.txt

Open a file and jump to a line:

vim +25 file.txt

Useful when reading logs or debugging code.


Vim Modes (The Key Concept)

Understanding Vim modes makes everything easier.

ModePurpose
Normal modeNavigate and run commands
Insert modeType text
Visual modeSelect text

Return to normal mode anytime:

Esc

Enter insert mode:

i

Other insert options:

See also: Mastering the Linux Command Line — Your Complete Free Training Guide

CommandBehavior
iinsert before cursor
ainsert after cursor
onew line below
Onew line above

Moving Around in Vim

Navigation is where Vim becomes powerful.

Basic movement

KeyMove
hleft
jdown
kup
lright

Faster navigation

CommandResult
wnext word
bprevious word
0start of line
$end of line

Jump in file

CommandResult
ggtop of file
Gbottom of file
:50go to line 50

Editing Text

Editing text is extremely efficient once you know a few commands.

Delete

CommandAction
xdelete character
dddelete line
dwdelete word

Copy and Paste

CommandAction
yycopy line
ywcopy word
ppaste after
Ppaste before

Example workflow:

yy
p

Duplicate a line instantly.


Undo and Redo

Everyone makes mistakes.

CommandAction
uundo
Ctrl + rredo

Undo multiple changes by pressing u repeatedly.


Searching in Vim

Search forward:

/word

Search backward:

?word

Next match:

n

Previous match:

N

Example:

/error

Jump through every occurrence of “error” in a log file.


Find and Replace

Replace text in Vim using this command:

:%s/old/new/g

Explanation:

PartMeaning
%entire file
ssubstitute
gall matches

Replace only in current line:

:s/old/new/g

Ask before replacing:

:%s/old/new/gc

Saving and Exiting

The most famous Vim commands:

CommandMeaning
:wsave file
:qquit
:wqsave and quit
:q!quit without saving

Shortcut:

ZZ

Save and exit quickly.


Visual Mode (Selecting Text)

Enter visual mode:

v

Select lines:

V

Block selection:

Ctrl + v

Useful for column editing or copying blocks of code.


Bonus: Speed Tricks

These small tricks make Vim feel magical.

Duplicate line:

yy
p

Join lines:

J

Repeat last command:

.

Example:

dw
.
.
.

Delete multiple words instantly.


Final Thoughts

Vim looks intimidating at first, but learning just a few core commands makes it extremely productive.

Start with:

  • navigation
  • insert mode
  • delete / copy
  • search
  • save and quit

Once these become muscle memory, editing files in the terminal becomes much faster than using a mouse.


Vim Cheat Sheet FAQ

1. How do I exit Vim if I’m stuck?
Press Esc then type :q! and hit Enter.

2. How do I save a file in Vim?
Use :w to write the file to disk.

3. What is the fastest way to delete a line in Vim?
Use dd.

4. How do I search for text in Vim?
Type /word then press Enter.

5. Why do developers prefer Vim?
Because it allows extremely fast keyboard-based editing once learned.

David Cao
David Cao

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

Articles: 597

Leave a Reply

Your email address will not be published. Required fields are marked *