Moving Around a File in vi

team bbl


Usually, you can use the arrow keys on your keyboard to move around the open file in vi. In some cases, such as a very old or very minimal Linux installation, the arrow keys don't operate.

You can always move around your file using the key commands in Table 18-1.

Table 18-1. Commands for Moving Around in a File

Key

What It Does

j

Moves cursor down one line.

k

Moves cursor up one line.

l

Moves cursor one character to the right.

h

Moves cursor one character to the left.

G

Moves cursor to the last line of the file.

L

Moves cursor to the last line on the screen.

Ctrl-d

Moves down one screen.

Ctrl-u

Moves up one screen.

:n

Moves the cursor to line n. For instance, :1 moves to the first line of the file.

$

Moves to the end of the current line.

^

Moves to the first non-space character in the current line.

0 (zero)

Moves to the beginning of the line.

w

Moves to the beginning of the next word.

b

Moves to the beginning of the previous word.

e

Moves to the end of the word.


NOTE

Be sure to use the correct case. vi is case sensitive. It doesn't see a and A as the same command.


In addition to the commands to move the cursor, you can move to specific text characters or strings by searching for them. You can search for a character in a line using the f (find) command. The syntax is fx, where x is the character to find. For instance, fh moves to the next h.

To search the entire file, press /. The cursor moves to the bottom of the screen. Type the text to search for. When you press <Enter>, the cursor moves to the next instance of the text. After finding one instance of the text, just press / again to search further for the same text. Use ? to search backward through the file.

    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net