vi Editor
--------

Getting to the prompt

In order to access vi, you must first be at a Terminal prompt to call on the editor.

If you are at a Solaris workstation,


If you haven't already done so, right-click on the Terminal icon and then click on Put in Workspace.
This action creates a shortcut to the prompt on your desktop.

Getting In and Out The first thing to learn about an editor is how to enter it, and how to get out. The UNIX command: vi invokes the editor on a file named filename, where filename is the name of an existing file you want to edit, or of a new file you want to create. Getting out of vi and back to UNIX requires a special kind of command, one left over from the days of descriptive editing. Descriptive commands begin with a colon, which causes the cursor to jump to the screen;s last line. When the command is finished, the cursor goes back to where it belongs. Descriptive commands end with the ESCAPE key (Esc) or the Enter key. The command for leaving vi and saving the changes is x, for exit :x :wq :wq Shift-ZZ (if the file has been named already) More about vi Two modes: Insert and Command INSERT MODE: In this mode, you type text as you normally do. Hitting moves you to the next line. Hit to exit this mode. COMMAND MODE: This mode is used to navigate through the document, delete text, and perform other special commands. To enter Command mode, press . Commands to navigate through the document while in Command mode: h move one space to left G move to last line of document l (little L) move one space to right nG move to line n in document w move forward one word ctrl-d move down 1/2 screen b move back one word ctrl-f move down 1 screen j move one line down ctrl-u move up 1/2 screen k move one line up ctrl-b move up 1 screen 0 (zero) move to column 1 n| (n, pipe) move to column n $ move to end of current line Text deletion commands x delete character under cursor x Specify a number and hit x - Deletes n characters dd deletes current line ndd deletes n lines, staring with current line D deletes from current position to end of line u UNDO: undoes the most recent command (note: this must be done IMMEDIATELY after offending delete or paste) Copy-and-paste (yanking) yy yank current line yy yank n lines p paste on line after cursor P paste on current line Commands that move you to Insert mode i insert at current cursor position I (big i) insert at beginning of current line a insert to the right of current position A insert at end of current line o insert in a new line after current line O insert in a new line before current line Special commands performed from Command mode % when cursor is on a bracket or parenthesis, will move cursor to matching bracket :f shows current line number :/string searches from current position for string. Leaves cursor at first instance of string n jumps to next occurrence of string :wq save file and quit vi :w save file :w name save file with filename name :q! quit vi without saving file One Additional Command Occasionally when you are working in vi the screen will need to be refreshed. To redraw the screen you can can use ctrl-l This is not a comprehensive list of vi commands. There are many more.