Open file
vim file.txt
Exit Vim (without saving)
:q!
Save and exit
:wq
Or simply:
:x
Save without exiting
:w
Enter Insert mode
Press i (insert before cursor) or a (append after cursor).
Exit Insert mode
Press Esc.
Delete a line
In Normal mode: dd
Undo
u
Redo
Ctrl+r
Search for text
/search_term
Press n for next match, N for previous.
Replace text
Replace "old" with "new" in entire file:
:%s/old/new/g
Go to line number
:42
Copy (yank) line
yy
Paste
p
Delete from cursor to end of line
d$
Show line numbers
:set number