Tải bản đầy đủ - 0 (trang)
The vi Editor (Linux in a Nutshell, 3rd Edition)

The vi Editor (Linux in a Nutshell, 3rd Edition)

Tải bản đầy đủ - 0trang

The vi Editor (Linux in a Nutshell, 3rd Edition)







vi command-line options







ex command-line options







Movement commands







Edit commands







Saving and exiting







Accessing multiple files







Interacting with the shell







Macros







Miscellaneous commands







Alphabetical list of keys in command mode







Syntax of ex commands







Alphabetical summary of ex commands







vi configuration (setting options at startup)



For more information, see the O'Reilly book Learning the vi Editor by Linda Lamb and

Arnold Robbins.



11.1. Review of vi Operations

This section provides a review of the following:





Command-line options







vi modes







Syntax of vi commands







Status-line commands



11.1.1. Command Mode

file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_01.htm (2 of 6) [15/05/2002 18:10:46]



The vi Editor (Linux in a Nutshell, 3rd Edition)



Once the file is opened, you are in command mode. From command mode, you can:





Invoke insert mode







Issue editing commands







Move the cursor to a different position in the file







Invoke ex commands







Invoke a Linux shell







Save or exit the current version of the file



11.1.2. Insert Mode

In insert mode, you can enter new text in the file. Press the Esc or Ctrl-[ keys to exit insert

mode and return to command mode. The following commands invoke insert mode:

a

Append after cursor

A

Append at end-of-line

c

Begin change operation (must be followed by a movement command)

C

Change to end-of-line

i

Insert before cursor

I

Insert at beginning of line



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_01.htm (3 of 6) [15/05/2002 18:10:46]



The vi Editor (Linux in a Nutshell, 3rd Edition)



o

Open a line below current line

O

Open a line above current line

R

Begin overwriting text

s

Substitute a character

S

Substitute entire line



11.1.3. Syntax of vi Commands

In vi, commands have the following general form:

[n] operator [m] object

The basic editing operators are:

c

Begin a change

d

Begin a deletion

y

Begin a yank (or copy)

If the current line is the object of the operation, then the operator is the same as the object: cc,

dd, yy. Otherwise, the editing operators act on objects specified by cursor-movement

commands or pattern-matching commands. n and m are the number of times the operation is

file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_01.htm (4 of 6) [15/05/2002 18:10:46]



The vi Editor (Linux in a Nutshell, 3rd Edition)



performed or the number of objects the operation is performed on. If both n and m are

specified, the effect is n × m.

An object can represent any of the following text blocks:

word

Includes characters up to a space or punctuation mark. A capitalized object is a variant

form that recognizes only blank spaces.

sentence

Extends to ., !, ? followed by two spaces.

paragraph

Extends to next blank line or nroff/troff paragraph macro (defined by para= option).

section

Extends to next nroff/troff section heading (defined by sect= option).



11.1.3.1. Examples

2cw

Change the next two words

d}

Delete up to next paragraph

d^

Delete back to beginning of line

5yy

Copy the next five lines into temporary buffer (for future pasting)

y]]

Copy up to the next section into temporary buffer (for future pasting)

file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_01.htm (5 of 6) [15/05/2002 18:10:46]



The vi Editor (Linux in a Nutshell, 3rd Edition)



11.1.4. Status-Line Commands

Most commands are not echoed on the screen as you input them. However, the status line at

the bottom of the screen is used to echo input for the following commands:

/

Search forward for a pattern

?

Search backward for a pattern

:

Invoke an ex command

!

Pipe the text indicated by a subsequent movement command through the following

shell command, and replace the text with the output of the shell command

Commands that are input on the status line must be entered by pressing the Return key. In

addition, error messages and output from the Ctrl-G command are displayed on the status

line.



10.5. Summary of

Commands by Name



11.2. vi Command-Line

Options



Copyright © 2001 O'Reilly & QKFIN. All rights reserved.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_01.htm (6 of 6) [15/05/2002 18:10:46]



vi Command-Line Options (Linux in a Nutshell, 3rd Edition)



Linux in a Nutshell, 3rd

Edition



11.2. vi Command-Line Options

The three most common ways of starting a vi session are:

vi file

vi + n file

vi +/ pattern file

You can open file for editing, optionally at line n or at the first line matching pattern. If no file

is specified, vi opens with an empty buffer. The command-line options that can be used with

vi are:

+[num]

Start editing at line number num, or the last line of the file if num is omitted.

+/pattern

Start editing at the first line matching pattern. (Fails if nowrapscan is set in your .exrc

startup file.)

-c command

Run the given vi command upon startup. Only one -c option is permitted. ex

commands can be invoked by prefixing them with a :. An older form of this option,

+command, is still supported.

-e

Run as ex (line editing rather than full-screen mode).

-l

Enter LISP mode for running LISP programs (not supported in all versions).



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_02.htm (1 of 2) [15/05/2002 18:10:49]



vi Command-Line Options (Linux in a Nutshell, 3rd Edition)



-r [file]

Recover and resume editing on file after an aborted editor session or system crash.

Without file, list files available for recovery.

-t tag

Edit the file containing tag and position the cursor at its definition (see ctags in

Chapter 3, "Linux Commands" for more information).

-v

Run in full-screen mode (default).

-w rows

Set the window size so rows lines at a time are displayed; useful when editing over a

slow dial-up line.

-x

Prompt for a key that will be used to try to encrypt or decrypt a file using crypt (not

supported in all versions).

-C

Same as -x, but assume the file is encrypted already (not supported in all versions).

-L

List files that were saved due to an aborted editor session or system crash (not

supported in all versions).

-R

Edit files read-only.



11. The vi Editor



11.3. ex Command-Line

Options



Copyright © 2001 O'Reilly & QKFIN. All rights reserved.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_02.htm (2 of 2) [15/05/2002 18:10:49]



ex Command-Line Options (Linux in a Nutshell, 3rd Edition)



Linux in a Nutshell, 3rd

Edition



11.3. ex Command-Line Options

While most people know ex commands only by their use within vi, the editor exists also as a

separate program and can be invoked from the shell (for instance, to edit files as part of a

script). Within ex, you can enter the vi or visual command to start vi. Similarly, within vi, you

can enter Q to quit the vi editor and enter ex.

If you invoke ex as a standalone editor, you can include the following options:

+[num]

Start editing at line number num, or the last line of the file if num is omitted.

+/pattern

Start editing at the first line matching pattern. (Fails if nowrapscan is set in your .exrc

start-up file.)

-c command

Run the given ex command upon start-up. Only one -c option is permitted. An older

form of this option, +command, is still supported.

-e

Run as a line editor rather than full-screen vi mode (default).

-l

Enter LISP mode for running LISP programs (not supported in all versions).

-r [file]

Recover and resume editing on file after an aborted editor session or system crash.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_03.htm (1 of 3) [15/05/2002 18:10:52]



ex Command-Line Options (Linux in a Nutshell, 3rd Edition)



Without file, list files available for recovery.

-s

Silent; do not display prompts. Useful when running a script. This behavior also can be

set through the older - option.

-t tag

Edit the file containing tag and position the cursor at its definition (see ctags in

Chapter 3, "Linux Commands" for more information).

-v

Run in full-screen mode (same as invoking vi).

-w rows

Set the window size so rows lines at a time are displayed; useful when editing by a

slow dial-up line.

-x

Prompt for a key that will be used to try to encrypt or decrypt a file using crypt (not

supported in all versions).

-C

Same as -x, but assume the file is encrypted already (not supported in all versions).

-L

List files that were saved due to an editor of system crash (not supported in all

versions).

-R

Edit files read-only; do not allow changes to be saved.

You can exit ex in several ways:

:x

Exit (save changes and quit).

:q!

Quit without saving changes.

:vi

file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_03.htm (2 of 3) [15/05/2002 18:10:52]



ex Command-Line Options (Linux in a Nutshell, 3rd Edition)



Enter the vi editor.



11.2. vi Command-Line

Options



11.4. Movement Commands



Copyright © 2001 O'Reilly & QKFIN. All rights reserved.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_03.htm (3 of 3) [15/05/2002 18:10:52]



Movement Commands (Linux in a Nutshell, 3rd Edition)



Linux in a Nutshell, 3rd

Edition



11.4. Movement Commands

A number preceding a command repeats the movement. Movement commands are also

objects for change, delete, and yank operations.



11.4.1. Character

Command



Action



h, j, k, l



Left, down, up, right (



Spacebar



Right



,



,



,



)



Backspace Left

Ctrl-H



Left



11.4.2. Text

Command Action

w, b



Forward, backward by word (treating punctuation marks as words).



W, B



Forward, backward by word (recognizing only whitespace, not punctuation,

as separators).



e



End of word (treating a punctuation mark as the end of a word).



E



End of word (recognizing only whitespace as the end of a word).



), (



Beginning of next, current sentence.



}, {



Beginning of next, current paragraph.



]], [[



Beginning of next, current section.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch11_04.htm (1 of 4) [15/05/2002 18:10:55]



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

The vi Editor (Linux in a Nutshell, 3rd Edition)

Tải bản đầy đủ ngay(0 tr)

×