University of Minnesota Morris Computing Services

 
UMM Home > Computing Services > Guides > Text Editors > vi text editor

vi Text Editor

Introduction

vi (visual) is a display orientated interactive text editor. Using vi you may edit an old file or you may create a new file. The user may enter new text, delete text, delete lines of text, open new lines of text, and replace old text with new text.

Accessing the vi editor

Type: vi filename

The screen should clear and the text from your file should appear on the screen. The vi editor does not work directly with your file, instead it operates on a copy of your file. So you may make as many changes as you want and not affect your original file if you do not save your file when you exit vi. Note that Unix does not keep different versions of a file.

How to Save/Quit

:wwrite buffer
:qquit
:wqsave file and exit vi
:q!abandon buffer
(quit and don't save)
ZZsame as :wq
save file and exit vi
ctrl Zsuspend vi

How to Move the Cursor -

You will use the arrow keys on your keyboard to move your cursor around on the screen. If for some reason the arrow keys do not work on your terminal you may also use the following keystrokes to navigate.

kline up
jline down
lright space
hleft space
ctrl Dscroll down
wword forward
bword backward
eend of word
0 (zero)beginning of line
$end of current line
Gend of file
ctrl-Bpage backwards one page
ctrl-Fpage forward in the file
line number and press Ggo to a specific line number

How to Insert Characters

(To exit insert mode press esc.)
aafter cursor
Aat end of line
ibefore cursor
Iat beginning of line
oopen line below
Oopen line above
ywyank word (copy word - press p to paste the word elsewhere)
yy or Yyank line (copy line - press p to paste the word elsewhere)
pput

Change

cwword
cc or Sline
Crest of line
sunder cursor
rreplace character

Delete

dwword
ddline
Drest of line
xunder cursor
Xbefore cursor
xptranspose

Other Commands

uundo change
.repeat
/wordfind down (word is the word you are trying to find)
?find up
nnext
ctrl-Lrefresh the screen