Solaris Advanced User's Guide

Command Mode

When you open a file with vi, you are in command mode. In this mode, you can type commands to implement a wide range of functions. Most vi commands consist of one or two letters and an optional number. Usually, uppercase and lowercase versions of commands perform related but different functions. As an example, typing a appends the file to the right of the cursor, while typing A appends the file at the end of the line.

Most vi commands do not require that you press Return to execute them. Commands beginning with a colon (:), however, do require that you press Return after the command. Some discussions of the vi editor refer to commands that are preceded with a colon as a third, and uniquely separate mode of vi, last-line mode. This mode is so named because when you type the colon while in command mode, the colon and the remainder of what is typed appear on the bottom line of the screen. For the purpose of this discussion, however, all vi commands are initiated from command mode.

Commands that are preceded with a colon are actually ex commands. vi and ex are two separate interfaces to the same text-editing program. While vi is a screen-oriented interface, ex is a line-oriented interface. The full set of ex commands is available from within vi. When you press the colon, you are actually switching to the line-oriented, ex interface. This switch enables you to perform many file manipulation commands without ever leaving vi. See Using ex Commands, in this chapter, for further information.