Editing with vi



next up previous contents index
Next: vi Command Summary Up: GETTING FRIENDLY WITH Previous: Printing Files

Editing with vi

  The standard Unix text editor is vi is so called because it is ``visually'' oriented (at least compared to the line editors which the pioneers used on their teletypes while treading the Oregon Trail). The vi editor and its counterpart view display your file on your screen in a similar manner, with vi giving you the option of modifying the file in addition to looking at it. To edit an existing file, filename:   
% vi filename Edit filename with vi.
% view filename Read filename with vi.

Note: if filename does not yet exist, this first command will create it.

The vi editor has command and insert modes. Command mode is the default (this differs from most PC programs), and in it you move the pointer or cursor around the file, delete text, and save your work. In insert mode you enter text into the file. The editor always begins in command mode and returns to it after executing an insert mode command successfully. To enter insert mode, you type insert commands like i, o, I, O, cw, CW; to leave insert mode (return to command mode), hit the escape key (sometimes marked Esc, sometimes mapped onto ` [accent grave]). If at some point you are not sure of your mode or what is happening or you just like to see flashes or hear bells, you can make it a practice to be sure and hit esc-it will hurt nothing.      

 
Figure 1.2: Movement commands in vi for different objects. 

Sometimes you realize you have made changes you don't want, or you think your original had something in it your changed version doesn't and you want to go back to the original. You undo the harm of your last command with u, or undo all changes on the present line with U. If you think you may have really messed up your file, you may want to :q!, that is, quit without rewriting the file. (You can write it to a temporary file with :w temp and then quit in case you think you may have done some good.)





next up previous contents index
Next: vi Command Summary Up: GETTING FRIENDLY WITH Previous: Printing Files