< Previous | Contents | Next >
Moving The Cursor Around
While in command mode, vi offers a large number of movement commands, some of which it shares with less. Here is a subset:
Table 12-1: Cursor Movement Keys
Key Moves The Cursor
Key Moves The Cursor
l or Right Arrow Right one character.
h or Left Arrow Left one character.
j or Down Arrow Down one line.
k or Up Arrow Up one line.
0 (zero) To the beginning of the current line.
^ To the first non-whitespace character on the current line.
$ To the end of the current line.
w To the beginning of the next word or punctuation character.
W To the beginning of the next word, ignoring punctuation characters.
b To the beginning of the previous word or punctuation character.
B To the beginning of the previous word, ignoring punctuation characters.
Ctrl-f or Page Down Down one page.
Ctrl-b or Page Up Up one page.
numberG To line number. For example, 1G moves to the first line of the file.
G To the last line of the file.
Why are the h, j, k, and l keys used for cursor movement? Because when vi was origi-
nally written, not all video terminals had arrow keys, and skilled typists could use regular keyboard keys to move the cursor without ever having to lift their fingers from the key- board.
Many commands in vi can be prefixed with a number, as with the “G” command listed above. By prefixing a command with a number, we may specify the number of times a command is to be carried out. For example, the command “5j” causes vi to move the cursor down five lines.