LukeSpence.com

opening a file with the vi editor

Make sure you login and are in your home directory. If you are already logged in, type cd to get back to your home directory. Then change to your vim subdirectory by typing cd vim. Type ls to see a listing of your files there. You should see one named vitutor. Type vi vitutor to open the file vitutor with the vi editor. Note: You must have completed one of the previous lessons in order to be able to this.

We will use the vitutor file as an in-class activity to get you used to working with the vi editor. Just for reference, the section below gives a table of vi editor commands that I think you will probably need at some point in the semester.

basic vi editor commands

When you open a file with vi, you are placed in command mode. If you are not sure what mode you are in, just type ESC and you will automatically be placed in command mode. The following commands will be helpful to know and can only be used while in command mode:

commands explanation
h move left
j move down
k move up
l move right
Contol-F scroll forward one screen
Contol-B scroll backward one screen
Contol-G display current line number
i insert text (places you in insert mode)
a append text (places you in insert mode)
r replaces character highlighted (with the cursor) with next character typed
x deletes character highlighted (with the cursor)
dw delete to end of word
d$ delete to end of line
dd delete current line
ndd delete next n lines
p put deleted text after cursor
u undo last edit
U restore current line
:! command give UNIX command
:r newfile read contents of newfile into current file
:w write (save) file
:q quit file
:wq write (save) and quit file
:q! quit file (discarding any unsaved changes)
:e! return to version of current file at time of last write (save)