Notes: Unix Lab 11

vi is a text editor. It does not format text. It does not (generally) set fonts, highlighting or anything else to the text document. It just edits the text data.

There are many variations of the vi editor but they are mostly attempts to extend the functionality of vi rather than alter its basic operation.

Why bother with it?

  1. vi is generally regarded as the "standard" unix editor. Probably every version of Unix includes the vi editor. You can be sure that vi will be available to you regardless of what version of Unix or Linux you are using.
  2. vi is very powerful. Like Unix in general, there is a vast array of features available but gaining the benefits requires some initial learning. Once proficient with vi, you may quickly make changes to files on any Unix host. vi has powerful search and replace functions and many other features useful when editing program code or other data.
  3. vi uses the terminal. vi does not depend on the graphical environment so it can be used to edit files on the local machine or using a remote shell on other hosts avialable to a networked unix machine.
  4. vi is fast. vi uses minimal system resources and is efficient on any machine capable of running unix.

Working with vi

  1. Starting vi
    vi is simply started from the command line with the command "vi". The file you wish to edit can be specified on the command line "vi newfile.txt" If the file specified does not exist then vi will be started with a blank edit buffer. If the file does exist, the contents of the file will be loaded in the edit buffer. Once started, vi has two basic "modes":
    1. command mode
    2. input mode
    Once started, vi should look something like this:

    In typical unix fashion, there is little visual information here. The cursor is in the upper left hand side of the terminal which is now the edit buffer. The editor is in command mode.
  2. Command mode

    By default, vi will be in command mode when it is started. This is the mode where commands may be given to the editor. Note that all commands in vi are case sensitive.
  3. Insert Mode

    From command mode, you may enter "insert mode" to begin inserting text by hitting the "i" character. This is the insert mode of vi. This will immediately allow any further characters you type to be inserted into the current file buffer (edit window). When you are done entering text and wish to get out of the insert command you need to hit the "escape" key. This will return vi back to command mode. "i" will cuase vi to start inserting text at the current cursor position. You may also start entering text with the "a" key/command which will allow you to append text starting at the next character to the right of the current cursor position.

    iinsert text
    a append text


Other resources:

last updated: 20 Aug 2014 14:40