viCommands

vihas two modes:

Command Mode: In command mode, commands can be entered which allow you to jump to points in a file, search text, and exit the editor.

Insert Mode: Insert mode allows you to create or alter text in a file.

Note: Commands are case sensitive.

Table 32 Basic vi Commands

Command

Description

 

 

vi filename

Opens the specified file in the editor. If the filename does not exits, vi creates it. Enter

 

this command from the Unix shell prompt.

(Escape Key)

Exits Insert Mode and enters Command Mode.

 

 

(Arrow Keys)

Moves the cursor up, down, left, and right.

 

 

i

Enters Insert Mode and allows you to insert text at the current cursor position.

 

 

x

Deletes the character at the current cursor position.

 

 

{/ ? } text

• The command / text Searches for the specified text in the forward direction.

• The command ? text searches for the specified text in the backwards direction.

 

[n 1]G

• The command nG moves the cursor to the specified line, where n is the line num-

ber.

 

 

• The command 1G moves the cursor to the first line in the file.

 

• The command G moves the cursor to the last line in the file.

0

Moves the cursor to the beginning of the current line.

 

 

$

Moves the cursor to the end of the current line.

 

 

:set {number no

Turns the line numbers on and off.

number}

 

 

 

:q!

Exits the editor without saving changes.

 

 

 

:wq

Saves changes and exits the editor.

 

 

126

Appendix D

Page 126
Image 126
Force10 Networks 100-00055-01 manual Vi Commands, ? text, Set number no, Number