vim movement key explaination

摘要:本文介绍所有的 VIM 关于移动的按键。

参考该文章:http://vim.wikia.com/wiki/All_the_right_moves

Vim provides many ways to move the cursor. Becoming familiar with them leads to more effective text editing.

1
2
3
4
5
6
7
8
9
10
h   move one character left
j move one row down
k move one row up
l move one character right
w move to beginning of next word
b move to previous beginning of word
e move to end of word
W move to beginning of next word after a whitespace 大写的区别在于只使用空格作为分割标准
B move to beginning of previous word before a whitespace
E move to end of word before a whitespace

举个例子

1
Vim provides many ways to move the cursor. Becoming familiar w

当光标在 cursor 的时候,如果使用 w,将会定位到句号,但是当使用 W,将会定位到 B。因为 W 只认为空格是单词分割符。
同理:对于 bB,如果光标在 Becoming 第一个字符,如果使用 b 将会定位到句号,但是 B 将会定位到 cursor
对于 eE,如果光标在 cursor 第一个字符,那么如果使用 e 竟会定位到 r,但是 E 将会定位到句号。

虽然大多数情况下,大写看上去表现一致,但是我们需要知道原因,因为没有其他符号。

All the above movements can be preceded by a count; e.g. 4j moves down 4 lines.

1
2
3
4
0   move to beginning of line
$ move to end of line
_ move to first non-blank character of the line
g_ move to last non-blank character of the line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
gg  move to first line
G move to last line
ngg move to n'th line of file (n is a number; 12gg moves to line 12)
nG move to n'th line of file (n is a number; 12G moves to line 12)
H move to top of screen
M move to middle of screen
L move to bottom of screen

zz scroll the line with the cursor to the center of the screen
zt scroll the line with the cursor to the top
zb scroll the line with the cursor to the bottom

Ctrl-D move half-page down
Ctrl-U move half-page up
Ctrl-B page up
Ctrl-F page down
Ctrl-O jump to last (older) cursor position
Ctrl-I jump to next cursor position (after Ctrl-O)
Ctrl-Y move view pane up
Ctrl-E move view pane down

n next matching search pattern
N previous matching search pattern
* next whole word under cursor
# previous whole word under cursor
g* next matching search (not whole word) pattern under cursor
g# previous matching search (not whole word) pattern under cursor
gd go to definition/first occurrence of the word under cursor
% jump to matching bracket { } [ ] ( )

fX to next 'X' after cursor, in the same line (X is any character)
FX to previous 'X' before cursor (f and F put the cursor on X)
tX til next 'X' (similar to above, but cursor is before X)
TX til previous 'X'
; repeat above, in same direction
, repeat above, in reverse direction

See :help {command} (for example, :help g_) for all of the above if you want more details.