There's a joke about Vim users: they spend weeks configuring their editor, then spend 20 minutes actually editing files. It's funny because it's true. But here's the thing - once you actually learn Vim, you never go back.
The Modes
Vim is not like other editors. It has modes. This confuses everyone at first:
- Normal - Move around, delete, copy. This is where you spend 90% of your time.
- Insert - Actually type text. Press
ito enter. - Visual - Select text. Press
v. - Command - Run commands. Press
:
Movement
Learn these keys. They're your new home:
h j k l # Left, Down, Up, Right
w # Word forward
b # Word backward
0 # Start of line
$ # End of line
gg # Top of file
G # Bottom of file
:20 # Go to line 20
% # Jump to matching bracket
Editing
Once you're in Normal mode:
x # Delete character
dw # Delete word
dd # Delete line
u # Undo
Ctrl+r # Redo
yy # Yank (copy) line
p # Paste
cw # Change word (delete + insert)
Search and Replace
Find things. Replace things:
/pattern # Search forward
?pattern # Search backward
n # Next match
N # Previous match
:%s/old/new/g # Replace all
:%s/old/new/gc # Replace all with confirm
Save and Quit
The commands everyone needs but forgets:
:w # Save
:w! # Save (force)
:q # Quit
:q! # Quit (don't save)
:wq # Save and quit
:x # Save and quit (shorter)
ZZ # Save and quit (even shorter)
Windows and Buffers
Vim isn't just one file:
:sp file # Split horizontal
:vsp file # Split vertical
Ctrl+w # Window navigation
:bn # Next buffer
:bp # Previous buffer
:bd # Close buffer
The Point
Vim is old. It looks weird. It has a learning curve that makes you want to quit. But it's on every server you'll ever touch. It's faster than anything with a mouse. It respects your freedom because it's free software and it doesn't try to be an IDE.
Learn Vim. Not because it's cool - because it makes you faster. Because when you're on a broken server at 3am, you want to be editing files as fast as possible.
The mouse is slow. Vim is fast. That's all that matters.