hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article238.htm

Không rõ

VI Editor : Just Enough to Get By

As the heading suggests, in this section I attempt to present a subset of the vi commands large enough to enable you to accomplish basic tasks, but small enough that a beginner can remember most of them.

Opening and Closing

You open a file by typing "vi " on the command line— for example: vi chapter29.txt

You close a file by getting into command mode (use the key), typing a colon ":" and then typing wq (write quit). If you don't want to save changes to the file, type q (quit). If it gives you any trouble, type wq! (enthusiastic quit).

Inserting Text

You insert new text by getting into edit mode. There are a lot of ways to get into edit mode. An incomplete list is presented next:

Key Function

i Insert new text at current cursor position.

A Append new text to the end of the current line.

Deleting Text

Delete text by getting into command mode (press ) and using one of the following keys:

Key Function

x Delete a character.

dw Delete a word.

dd Delete a line.

Moving Around

Get into command mode by pressing . The following keys are active:

Key Function

h Left one space

j Down one line

k Up one line

l Right one space

Undo

The undo key is "u". Get into command mode (press ) and then press "u". This will undo all the changes back to the last time you entered edit mode. You may press undo repeatedly, each time undoing an edit session.

Searching :Search for text by

1. Getting into command mode (press ).

2. Press the forward slash "/". A forward slash character should appear in the lower left corner of your screen.

3. Typing the string you wish to search for.

Starting and Stopping vi

vi can be invoked from the command line as follows:

Command Effect

vi -r file Recover a buffer saved when vi terminates.

vi +n file Open file on line n.

vi + file Open a file at the last line of file.

vi +/pattern file Open file at the first instance of pattern.

vi file file... Open multiple files.

Once inside vi, to get to the next file, type :n from command mode.

view file Open file in read-only mode.

The following commands will either get you out of vi, write any changes you may have made, or both:

Key Function

:w file Write to the specified file.

:w! file Write to specified file, regardless of file permissions.

:wq Write and quit.

:wq! Write and quit, regardless of access mode.

, ZZ Quit and save any changes.

:q Quit.

:q! Quit without saving changes.

Q Quit vi and start ex.


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com