vim — The Programmer's Editor
vim has a reputation for being hard to exit — but once you learn it, you'll be fast.
Opening files
vim filename.txt
vim +50 file.txt # Open at line 50
vim +/searchterm file # Open at first match
THE MOST IMPORTANT THING: Modes
vim has modes:
| Mode | How to enter | What it does |
|---|---|---|
| Normal | Esc | Navigate, commands |
| Insert | i a o | Type text |
| Visual | v V | Select text |
| Command | : | Save, quit, search |
Basic workflow
- Open file:
vim file.txt - Press
ito enter Insert mode - Type your text
- Press
Escto return to Normal mode - Type
:wqto save and quit
Essential Normal mode keys
h j k l # Move left/down/up/right
w W # Next word
b B # Previous word
0 ^ # Start of line
$ # End of line
gg # Top of file
G # Bottom of file
50G # Go to line 50
/text # Search forward
n / N # Next/previous match
dd # Delete line
yy # Copy line
p # Paste
u # Undo
Ctrl+R # Redo
Insert mode entry points
i # Insert before cursor
a # Append after cursor
I # Insert at line start
A # Append at line end
o # New line below
O # New line above
Command mode (:)
:w # Save
:q # Quit
:wq or :x # Save and quit
:q! # Quit without saving
:w file # Save as file
:50 # Go to line 50
:%s/old/new/g # Replace all
:set number # Show line numbers
:syntax on # Syntax highlighting