vi editing  «Prev  Next»
Lesson 2 A review of vi
ObjectiveIdentify key concepts of vi.

vi review(Basic Commands)

This lesson provides a brief summary of key concepts and commands about vi.

Key Concepts

  1. The UNIX command to open a file in the vi editor is vi file.
  2. You can use vi in either of two modes of operation. In command mode, [1] you use the keyboard for moving the cursor or for switching to text mode. In text mode[2] , you use the keyboard to add text to a document. When you press the Escape key while in text mode, you return to command mode.
  3. Commands from vi's underlying ex editor[3] start with a colon (:). They take effect when you press Enter. Regular vi commands do not appear on your screen. They take effect immediately after you press the key.

Key commands

vi commandsDescription
:w, :q, :wq Write (save) changes, quit vi, or do both together
h, j, k, l Move one character at a time (left, up, down, right)
w, b Move forward or backward by words
W, B Move forward or backward by words, ignoring punctuation
), ( Move forward or backward by sentences
Ctrl-F, Ctrl-B, Ctrl-D, Ctrl-U Move one screen forward or backward, or move half a screen down or up
i, a, o Insert before the cursor, append after the cursor, or open a blank line
c, d, y Operators for changing, deleting, or yanking (copying) text. Combine an operator with a movement command to create an editing command.
p, P Put buffer text after or before the cursor
., u, U Repeat last edit, undo last edit, or undo edits to current line

Movement commands and editing commands accept numeric multipliers[4]. For example, 5W moves the cursor ahead five words, and 3dd deletes three lines. In the next lesson, you will learn to search for text.

[1]command mode: Command mode is one of two modes of operation in vi. In command mode, you can move the cursor and issue editing commands, but you must switch to text mode to add text.
[2]text mode: Text mode is one of two modes of operation in vi. In text mode, you can use your keyboard to add text to your document.
[3]ex editor: ex is a line editor that serves as an underlying program for the vi editor. A line editor is a program in which you see only one line at a time.
[4]multiplier:In vi, a multiplier is a number that you place before a movement command or editing command to extend the range of the command.