The "vi" Screen Editor

"vi" is a popular and powerful text editor.

Command and Text Modes

There are two modes in the vi editor: the command mode and the text mode. The command mode lets you use different commands (that will be described later) in order to edit a file.

The text mode lets you use the keyboard to enter text. As soon as you invoke vi, you are placed in the command mode. To enter the command mode from text mode, press the <esc> key.

To enter the text mode, type any of the following commands (which will be described later on):

To:

Type:

append

a

insert

i

open line above

O

open line below

o

replace old text

R

substitute

s

Getting Started

The command for editing the file "filename" (for example) is:

vi filename If this file does not exist, the editor will create one when this command is typed.

Cursor Moving Commands

Commands used in vi are executed at the cursor location. The following commands enable you to move around the file in order to place the cursor in the desired location. The cursor will not move beyond existing text. Note that "#" should be substituted with a number specified by the user.

To:

Type:

move the cursor down one line

j

move the cursor up one line

k

move the cursor to the left

h

move the cursor to the right

l

move the screen down half a page

^d

move the screen up half a page

^u

move the cursor to that line number

#G

Entering Text

All of these commands are terminated by pressing the <esc> key.

To:

Type:

append text after the cursor

a

insert text before the cursor

i

open a blank line below the cursor

o

open a blank line above the cursor

O

Deleting Text

Any of these commands can be preceded by a number in order to specify the number of characters, words, etc. to be affected.

To:

Type:

delete character under cursor

x

delete from cursor to beginning of next word

dw

delete the line that the cursor is on

dd

delete the rest of the sentence

d)

delete the rest of the paragraph

d}

Altering Text

All of these commands except "r" are terminated by pressing the <esc> key.

To:

Type:

replace the character under the cursor with the next character typed

r

write over the existing text beginning at cursor position

R

change word beginning at cursor position with next string typed

cw

change sentence beginning at cursor position with next string typed.

c)

Search Commands

To:

Type:

search for next occurrence of "string" (where string is specified by the user)

/string

search for previous occurrence of "string" (where string is specified by the user)

?string

repeat the last search command

n

Moving Text

To:

Type:

yank a copy of a line and place it in a temporary buffer

yy

put the last string yanked after the cursor position

p

put the last string yanked before the cursor position

P

yank a copy of a line, place it in a temporary buffer "a" (where "a" is a letter specified by the user)

"aY

Put the contents of buffer "a" after the cursor

"ap

Saving Text and Quitting the Editor

Editing takes place in a temporary work area and must be saved by writing it into a permanent file.

To:

Type:

write this file into the permanent file

:w

quit editing without keeping the most current changes

:q

emphatic form of quit to be used when :q does not work

:q!

write and quit

:wq

write and quit

ZZ

write lines # to # into another file called "other" (numbers are specified by user as well as the "other" file name)

#,#w other

Append lines # to # to another file called "other" (numbers are specified by user as well as the "other" file name)

#,#w >> other





aliasdocs@aw.sgi.com

Copyright © 1997, Alias|Wavefront, a Silicon Graphics Company. All rights reserved.