Vim命令简介

Esc: To enter Normal mode.
h: Move left
l: Move right
k: Move up
j: Move down
q!: Quit without saving
wq: Save a file and quit.
x: Delete character.
i: Insert character.
a: Append after the cursor.
A: Append in the end of the line.
Notice: i, a and A all go to the same Insert mode, the difference is where the characters are inserted.
dw: Delete a word.
d$: Delete to the end of the line.
dd: Delete a whole line.
ndd: Delete n lines
u: Undo the last commands
U: Fix a whole line.
CTRL+R : Redo the commands.
p: Put previously deleted text after the cursor.
rx: Replace the character at the cursor with x.
ce: Change until the end of a word.Notice that ce deletes the word and places you in Insert mode.
c [number] motion: Change opreator words in the same way as delete.
v: Starts visual selection.
o: Open a line below the cursor and place you in Insert mode.
O: Open a line above the cursor
R: Replace more than one character.Press Esc to leave Replace mode.
y: Copy(Yank) text.
p: Paste(Put) text.
yw: Copy one word.

Operator + [number] + Motion:
d – is the delete operator
motion – is what the operator will operate on
A short list of motions:
w – until the start of the next word, Excluding its first character.
e – to the end of the current word, Including the last character.
$ – to the end of the line, Including the last character.
Note: Pressing just the motion while in Normal mode without an operator will move the cursor as specified.

Using a count for a motion: Typing a number before a motion repeats it that many times.
Examples:
2w – move the cursor two words forward.
3e – move the cursor to the end of the third word forward.
0 – move the cursor to the start of the line.
CTRL+G: Show your location in the file and file status.
G: Move to the buttom of the file.
gg: Move to the start of the file.
numberG: Move to the line of the file.

/phrase<Enter>: Search for the phrase.
n: Search for the same phrase again.
N: Search for the same phrase in the opposite direction.
?phrase<Enter>: Search phrase in the backward direction.
CTRL+O: Go back to where you came from.
CTRL+I: Go forward.

%: find a matching 0,], or }.
Place the cursor on any (,[ or { and type % character,the cursor will move to the matching parenthesis or bracket.

:s/old/new/g: To replace ‘new’ for ‘old’,adding a g means to replace globally in the line.
:#,#s/old/new/g: Change every occurence of a character string between two lines.
:%s/old/new/g: Change every occurence in the whole file.
:%s/old/new/gc: with a prompt.

:! + command: Execute that command.
:w FILENAME: Save the changes made to the text.
:r FILENAME : Insert the content of a file.
:r !command: Insert the output of the command.

Reference:vimtutor

发表评论

电子邮件地址不会被公开。