Vi For Smarties

Lesson Five


Dangerous Pitfalls

  1. When you abort a command, ALWAYS hit Esc before continuing. It's easy to lose a lot of work if you forget this!
    Example: If you hit d to begin deleting a chunk of text, then change your mind and decide to go look at the last line of your file by hitting G, you'll lose the rest of your file starting from your current cursor position.
  2. Use :w to save your file regularly.
  3. Start vi with vi -r filename to recover the swap file of filename if you lost your editing session prematurely. The swap file may or may not be complete, but it's better than nothing.

Some Loose Ends

  1. Use J (uppercase) to Join two consecutive lines. Place the cursor on the first of the two lines.
  2. Use U (uppercase) to Undo all changes made to a line if and only if the cursor has not been moved off that line yet.
  3. Use o (lowercase) or O (uppercase) to open a new line. Lowercase o opens a new line beneath the current one, and uppercase O opens a new line above the current one.
  4. For a line marked with ma (replace the a with any desired character), use 'a (single normal quote) to return to the beginning of that line. Use `a (backquote) to return to the exact position marked within that line.
  5. When pasting something that does not contain a return or newline (such as a fragment of a line or a single word), p (lowercase) pastes the contents of a buffer after the current cursor position on the same line and P (uppercase) pastes the contents of a buffer before the current cursor position on the same line.
  6. In addition to the 26 lettered buffers (a-z) which can be accessed with the " double quote, there are also 9 numbered buffers (1-9) which can be accessed in the same way. The 1 buffer is the one that holds whatever was last cut or yanked from the text. If something else is cut or yanked, the 1 buffer's contents are moved to the 2 buffer and the new cut or yanked text then goes in the 1 buffer. If another piece of text is cut or yanked, the 2 buffer's contents go to the 3 buffer, the 1 buffer's contents go to the 2 buffer, and so on. You cannot directly choose a numbered buffer to use when cutting or yanking text. You can only choose a numbered buffer to use when pasting text.
    What this means: If you cut or yank something, then forget and accidentally cut or yank something else, the first item is not lost. It is moved to the 2 buffer. If you forget again, the first item is moved to the 3 buffer, the second item is moved to the 2 buffer, and the new item is in the 1 buffer. You would have to forget 9 times in order to completely lose a piece of cut or yanked text. Do not forget anything 9 times.

Display Control

  1. If you hit Q you will enter the line editor, ex. Type vi followed by the enter key to return to vi mode.
  2. Use z. (remember the dot) to redraw the screen. Rarely necessary.

Until you have mastered everything on this page, you are not ready for Lesson Six.


Copyright © 2001 jerry_y_wang@yahoo.com. All rights reserved.