For information on editing text in vi, see Changing Text. For the moment, you can correct your mistakes by backspacing and retyping a line before you press Return. Characters you type appear to the left of the cursor and push any existing characters to the right. Now type a few short lines of text, ending every line with a Return. This command removes vi from command mode and puts it into entry mode. To type text in the sample file paint, type the vi “insert” command i. If you press Esc while vi is already in command mode, the system beeps and the screen flashes, but no harm is done. If you're not sure which mode vi is presently in, simply press Esc to make sure it's in command mode and continue from there. Whenever you want to return vi to command mode, press Esc. These and other vi entry commands are covered in greater detail later in this chapter. Before you can type text in the file, you must type one of the vi entry commands, such as i (“insert”), to insert text at the current cursor location, or a (“append”), to insert text after the current cursor location. When you first open a vi file, it's always in command mode. However, if you remember just a few basic concepts from the beginning, you should be able to avoid most of the usual “vi stress.” Command mode is the default mode for vi.īecause vi doesn't indicate which mode you're currently in, distinguishing between command mode and entry mode is probably the single greatest cause of confusion among new vi users. You use entry mode to type text into a file, while command mode is used to type commands that perform specific vi functions. Two modes of operation in vi are entry mode and command mode. When you create a new file, as is the case with the example, the status line indicates that it is a new file. The last line of the screen, called the status line, shows the name of the file and the number of lines and characters in the file. You can then name the file later when you exit vi. Note that you can also start vi without specifying a file name by just typing vi. Blank lines are indicated by a vertical series of tildes (~). The cursor appears in the upper left corner of the screen. The vi editing screen appears in a moment: Figure 6–1 vi Editing Screen For the purposes of this example, paint should be a new file. If paint already exists, vi opens the existing file. Start vi and edit the file paint as shown in this example: The following sections describe how to start vi, type text in a file, save (write) the file, and quit vi. When you open a file with view, you can use vi commands, but you cannot accidentally change the file by saving your changes. The view utility is a read-only version of vi. As you begin to use vi, you will find that it is an extremely powerful text editor, and proficiency happens with practice. This chapter provides an overview of the most essential vi commands. Vi uses a variety of commands, many of which have functions that overlap. These programs enable you to format vi text by inserting codes that are then interpreted by the emulator. To produce formatted printouts, vi relies on a typesetting emulation program, such as nroff, troff, or ditroff. vi does not process formatted text in the familiar manner of a commercial word processor. You can type and edit text with vi, but it is not a word processor. vi is not window based and can be used on any kind of terminal to edit a wide range of file types. Vi (pronounced “vee-eye,” short for visual display editor) is the standard SunOS text editor.
0 Comments
Leave a Reply. |