A. Introductions
- Mode ( esc &i )
First status is normal mode after you start the vim editor. <command mode>
Press ' i ', switches to insert mode. <text mode>
Press ' esc ' return to normal mode.
- Common commands
x : delete current character.
:w : save to current file.
:w + filename: save as filename.
:q :quit.
:wq:save and quit.
dd : cut current line into clipboard.
p : paste the content of clipboard to terminal.
h : left;j: down; k : up; l: right.
:help [options] : help command documentation.
B. Texting
- Insert
a : insert a character after current cursor. (entries insert mode)
o : insert a new line after current line.
O : insert a new line before current line.
cw : delete the content from current position of cursor to the end of this line.
- Move cursor
0 : move to the begin of this line.
$ : move to the end of this line.
^ : move to the first visible character of this line.
g_ : move to the last visible character of this line.
/ + keyword : search the word after the symbol ' / ' . /* press ' n ' move to the next word which matching keyword */
- Copy / Paste
D : delete whole line.
yy : copy current line.
p : paste.
- Undo / Redo
u : undo.
ctrl + r : Redo /*need to be verified in MAC OS X */
- Open / Save / Quit / Change File (Buffer)
:e < path / to / file > : open a file.
:w : save.
:saveas < path / to / file > : save as another filename.
:x : save.
ZZ : save.
:q! : quit without save.
:bn : switch next file opened.
:bp : switch prior file opened.
C. More
- Repeat
. : repeat the command typed last time.
N <command> : repeat command typed last time as N times.
- Efficiency
NG : move to the Nth line.
gg : move to the first line.
G : move to the last line
w : move to the first letter of the next word.
e : move to the last letter of the next word.
W : same to the ' w ', but word separated as blank.
E : same to the ' e ', but word separated as blank.
* : move to the prior word which same to the current word.
# : move to the next word which same to the current word.
- Fast
<start position><command><end position>
For example:
ye : copy from current position to the last letter of next word.
yw : copy from current position to the first letter of next word.
y& : copy from current position to the end of this line.
y0 : copy from current position to the begin of this line.
v : highlight.
fa : move to the next character matching a.
ta : move to the position which before the next a.
Nfa : move to the Nth character matching a.
D. Some command do not work on Mac OS X
I won't translate them.