OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< 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.


image

h or Left Arrow Left one character.


image

j or Down Arrow Down one line.


image

k or Up Arrow Up one line.


image

0 (zero) To the beginning of the current line.


image

^ To the first non-whitespace character on the current line.


image

$ To the end of the current line.


image

w To the beginning of the next word or punctuation character.


image

W To the beginning of the next word, ignoring punctuation characters.


image

b To the beginning of the previous word or punctuation character.


image

B To the beginning of the previous word, ignoring punctuation characters.


image

Ctrl-f or Page Down Down one page.


image

Ctrl-b or Page Up Up one page.


image

numberG To line number. For example, 1G moves to the first line of the file.


image

G To the last line of the file.


image


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.


Top OS Cloud Computing at OnWorks: