Academic Computing Services
QUICK STUDY #24
March 2001

Using the UNIX Visual Editor (vi) on the RCS UNIX Platform

When working with UNIX on RCS (Rensselaer Computing System), you will probably need to use a text editor. Whether you are writing a program, writing a paper, or editing a usenet message, you are going to need to create, write, store, retrieve, view, and edit files, and vi is one of several text editors available on RCS. You can use vi from a RCS UNIX workstation on campus, or from a dial-up or SecureCRT connection from a PC to the RCS UNIX platfrom.

To start writing a new file in vi, or to view an existing vi file, enter the following command at a UNIX prompt, replacing filename with the name of an existing file, or the name of the new file you want to create:
\begin{alltt}\bf
vi {\it {}filename}
\end{alltt}
vi can be in different modes, the most common being command mode and insert mode. By default, when you start up vi, it is in command mode, which enables you to do things like navigate around in the file, delete lines, and so on. However, you need to be in insert mode in order to be able to insert new text in the file.

To change between modes, press the Escape (ESC) key. If you're ever in doubt when you're editing a vi file, or if you're stuck, press the ESC key, and try issuing your command. This should help you determine if you're in command or insert mode.

Moving Around in the File

To move around in the file, you can press the up or down arrow keys. The left and right arrow keys will move the cursor left or right. If you're accessing RCS from a remote connection, you might find that the arrow keys don't work.

If you press the up or down arrow key and a single character appears on each line as you go, you are in insert mode. Press the ESC key and try the arrow keys again.

If you encounter other problems, try these keys:

Move Key
up k or \(\uparrow\)
down j or \(\downarrow\)
backward h or \(\leftarrow\)
forward l or \(\rightarrow\)

Other ways to move around include:

Press This For This Function
CTRL-b scrolls one screen backward
CTRL-f scrolls one screen forward
G moves the cursor to the last line of the file
1G moves the cursor to the first line of the file

Inserting Text

To start entering text, type the vi command i. Do not press Enter or Return. The i that you pressed will not appear on the screen - you have just issued a command to vi, telling it that you want to insert text. Any character you type now will appear on your screen. (Also note that pressing arrow keys will cause random letters to appear.)

If you start typing, and the text you expect does not appear on the screen (perhaps nothing happens or you get single characters on several lines), you are in some mode other than insert mode. Press the ESC key, issue the insert command (press i), and resume typing. Press Return or Enter at the end of every line; the text does not automatically wrap within the UNIX window.

Deleting Text

Press the Escape key to enter command mode. Place the cursor over the character you want to delete and press the x key.

To delete an entire word and the space after it, place the cursor on the first letter of the word and type dw for delete word. The word will disappear.

To delete an entire line, type dd.

To delete to the end of the line, type D.

Undoing Mistakes

To undo the command you just issued, press Escape and then press u. Only commands that involve editing can be undone.

Saving Your Work as You Go

If you are typing a long file, or doing a lot of editing, you might want to save your work as you go. This way, if some problem occurs or someone trips over the plug to your computer, most of the work you have done will be saved. If you lose access to your file and you haven't saved it while you were working, all your work will be lost. To save your most recent changes, first press the Escape key to enter command mode, then type :w. (This command will appear on the command line at the bottom of the screen or window.) Finally, press Enter or Return. Doing this will save your work and keep you within the vi editor.

Exiting vi

To save any changes to your file and then exit the vi editor, press the Escape key and type :wq (for write and quit), then press Enter or Return to execute the command. You may also save any changes and exit vi by pressing the Escape key and then entering the command ZZ (note the capitals). As you're working, you might also decide that you do not want to save your changes, and that you wish to exit vi and leave your file as it was when you started. To do this, press the Escape key to enter command mode, then type :q! or :quit! and press Enter or Return.


About this document ...

Published by Academic Computing Services, RPI, Troy, NY 12180

Send comments to consult@rpi.edu.