1. Operating Modes
- Normal: for moving around a file and making edits, press
<ESC>
to switch from any mode back to Normal mode. - Insert: for inserting text, press
i
in normal mode to enter Insert mode. - Replace: for replacing text, press
r
in normal mode to enter Replace mode. - Visual: for selecting blocks of text, press
v/V
in normal mode to enter Visual / Visual Line mode, press<C-v>
to enter Visual Block mode. - Command-line: for running a command, press
:
in normal mode to enter Command-line mode.
2. Basic
Command-line
:q
quit:q!
quit anyway (without making any change):w
write (save):wq
write and quit:e {name of file}
open file for editing:ls
show open buffers:help {topic}
show open buffers
Movement
- Basic movement:
hjkl
(left, down, up right) - Word:
w/W
(next word),b/B
(beginning of last word),e/E
(end of word) - Lines:
0
(beginning of line),^
(first non-blank character),$
(end of line),{
/}
(beginning / end of a paragraph) - Screen:
H
(head of screen),M
(middle of screen),L
(bottom of screen) - Scroll:
<C-u/f>
(page-up / forward),<C-d/b>
(page-down / backward),<C-e>
(scroll up),<C-y>
(scroll down) - File:
gg
(beginning of file),G
(end of file) - Line numbers:
:{number}<CR>
or{number}G
(go to line {number}) - Misc:
%
(corresponding item) - Find:
f{character}
(find),F{character}
(find backward),t{character}
(till),T{character}
(back till), use,/;
to repeat operations. - Search:
/{regex}
/?{regex}
,n
/N
for navigating matches
Selection
Use Visual modes
Edit
o
/O
insert line below / aboved{motion}
e.g.dw
- delete word,d$
- delete to end of line,d0
- delete to beginning of linec{motion}
e.g.cw
- change wordx
delete characters
substitute character ( =xi
)u
undo,<C-r>
redoy
copy / yank,Y
copy linep
paste
Counts
verb + num + noun
Modifiers
i
insidea
around
3. Advanced
Search and Replace
%s
substitute command
:%s/x/y/g " change all x to y
Multiple Windows
:sp
/:vsp
split windows