|
vi operates in one of two modes. vi behaves differently, depending on which mode it's in:
vi opens a file in Normal mode. vi changes to insert mode when you enter a command that inserts text into a file. For instance, the <i> key is the insert command. It changes vi to insert mode and allows you to type text into the file. vi stays in insert mode until you press <Esc>, which ends Insert mode and returns to Normal mode. Another command that changes vi to insert mode is <a>, the append command, which allows you to insert text after the cursor. In Normal mode, keys are commands. Most commands are one key, although some require a two key sequence. Almost all the commands allow you to type a number before the command. The command is repeated the number of times specified by the number. For instance, <dd> is the command to delete a line. <3dd> deletes 3 lines. If you enter no number before the command, the number 1 is assumed. A small set of vi commands is described in this chapter. This set is sufficient for most editing tasks. However, vi has many abilities not presented here. If you often edit at the command line, you will appreciate learning more of vi's capabilities. See the vi (or vim) documentation on your system for complete documentation. After adding/editing the file content as described in the remainder of this chapter, save the file by pressing <ZZ> (notice that ZZ is uppercase). You can close a file without saving any changes by typing: :q! You can save a file without exiting vi with the command :w. |
|