Unix vi Quick Notes to help you with the homework for session 2

  1. From your command shell, start vi by typing vi
  2. Insert characters by switching from the default command mode to input mode by typing i
  3. Append characters in the input mode by typing a
  4. Start a new line by pressing Enter
  5. Switch back to command mode by pressing Esc
  6. Write your work to a file by typing :w file_name
  7. Quit vi without saving again by typing ZZ
  8. Open vi with a new empty file by typing vi second_file
  9. Add the day and time by typing i day time
  10. Write your file (save your work) and quit vi by typing :qw
  11. Open one of your files and quit without making changes by typing :q

To quit, type :q
To quit without saving any changes, type :q! (colon q bang).
To write your changes to an file that you name when you save the file, type :w filename, then press enter.

To return to command mode, type Esc

To navigate
use your right hand in its normal keyboard position,
index finder on j = move cursor down one line
middle finger on k = move cursor up one line
ring finger on l = move right one space
index finger on h = move left one space

0 (zero) moves the cursor to the zero position of the line, that is, the beginning.
$ moves the cursor to the end of the line (dollars are the end, or goal?)

Ctrl-f moves forward one screen
Ctrl-b moves backward one screen (think "b" for backward)

w moves forward    one word
b moves backward one word

o opens a new line (moves you to the start of the next line to originate a new line)
dd deletes the current line

An Exercise in Substitution

Create a file called NASA and on several of the lines put the string NASA.

Substitute the string Cosmonaut for that of NASA by typing the command

;1,33 s/NASA/Cosmonaut

This command substitutes the string "NASA" with that of "Cosmonaut" for lines 1 through 33 of the current file.

copyleft copyleft.gif (70 bytes) 1999 Thomas Albert