|
|
|
||||||
|
Using viQUICK GUIDE TO vi ON UNIXPlease note that UNIX commands are case sensitive. Be sure to type commands exactly as they are shown in upper or lowercase. TWO UNIX EDITORSvi is one of two supported editors available on the Statistics UNIX system; emacs is the other. To create or edit any files on the UNIX system, or to post messages to any of the more than 700 bulletin boards and newsgroups available through the rn or Pnews programs, you need one of the editors. STARTING VITo invoke the vi editor, type vi at the UNIX shell prompt. If you do not indicate a file name, vi will display a blank screen with the number 1 at the top line and subsequent lines starting with the tilde (~) character. To begin and name a new file at the same time, or to edit a file already created, type vi filename. As you input text and press return/enter at the end of each line, the ~ on each line is replaced with the line number. Esc + COMMANDSPerforming any editing functions, such as moving the cursor without using the arrow keys, inserting and deleting text, changing or overwriting text, saving files, and exiting the editor, is at least a two-step process. Every vi command is initiated by pressing the esc key first. CURSOR MOVEMENTWith cursor movement, for example, you can use the arrow keys to move around in your file or you can use the following vi commands. The commands with (n) enable you to specify an optional number of characters, words, etc, to move past; the default is one unit.
TYPING/INSERTING TEXTTo start a file after invoking vi, press esc, type i or a, then begin typing. Always remember to press the enter/return key at the end of each line; (Note: if you have accessed vi through the rn or Pnews program and you are editing a message file to be posted to a newsgroup, insert a blank line as the first line of your message and begin typing at line 2.) As with cursor movement, vi provides different ways to insert text in addition to the i command. These commands, which must be preceded by esc, appear in the following list.
DELETING TEXTTo correct a mistake, position the cursor in the appropriate position, press esc, then enter one of the following commands:
SAVING A FILEWhen you finish editing your text, you can save the file in several ways. Saving a file is accomplished through one of the file management functions that are executable only on the bottom line of the screen. To access the bottom line, press esc and type a colon (:), which displays at the bottom line. Then type one of the commands from this list, then press return/enter: BOTTOM-LINE COMMANDS
COMPLETING A FILE; EXITING VIThe bottom-line commands provide several ways to end the editing session. Using any of the commands from the list above, you can exit the current file saving your changes, exit without saving changes, or move to the next file if you specified a list of file names when you invoked vi. EXAMPLE PROCEDURENow let's go through the procedure of creating, editing, and saving a file using vi and a few of the more common commands. We'll begin by creating the file named "announcement" that appears in the previous examples. Type the command in this form at the UNIX shell prompt: {username 52} vi announcement The cursor appears to the right of the number 1 at the top line. Press esc followed by the command i, and begin typing. On the bottom line in the right-hand corner a message tells you that you are in INPUT MODE. When you finish entering text. To make any changes to the text, use the arrow keys to position the cursor or press esc and type nj to move the cursor down to the appropriate line (where n is the number of lines you want to jump over). Press esc followed by one of the commands to insert, add, delete, or overwrite text. When you are ready to save the file, press esc followed by : to access the bottom command line. Type w or w filename and press return/enter to write (save) this version of the file and return to the current edit session. Type wq or wq filename to save the file and exit the edit session. OTHER FEATURESYou also can make changes to a file by using some of the specialized commands, shown below, which should be self-explanatory. As with the other commands, these also are preceded by esc.
ONLINE HELPIf you need assistance, you can get help from the online UNIX manual by typing man vi at the UNIX shell prompt. |
|
If you have trouble accessing this page, or need an alternate format contact webmaster@stat.osu.edu. |