-
gg
Go to the first line of the file. -
G (Shift + g)
Go to the last line of the file. -
0
Move to the beginning of the current line. -
$
Move to the end of the current line.
-
o
Open a new line below and enter Insert mode. -
O
Open a new line above and enter Insert mode.
-
/word
Search forward for "word" in the file. -
?word
Search backward for "word". -
n
After a search, go to the next match. -
N
Go to the previous match after a search.
- :%s/word/newword/g
Replace all instances of "word" with "newword" in the entire file.
-
dd
Delete (cut) the current line. -
dw
Delete a word (from the cursor forward).
-
y
Yank (copy) the selected text or line (yyfor the whole line). -
p
Paste the yanked or deleted content after the cursor.
-
:set nu
Show line numbers. -
:set nonu
Hide line numbers.
-
u
Undo the last change. -
Ctrl + r
Redo the last undone change.
To clear the entire content of a file in Vim:
- Press
Escto make sure you're in Normal mode. - Type: :1,$d