Vi For Smarties

Lesson Two


Cut and Paste

  1. yy yanks the current line into the buffer. This is like copying the current line to the clipboard.
    Example: 3yy yanks three lines into the buffer starting with the current one.
  2. p (lowercase) pastes the buffer contents to the line under the current one.
  3. P (uppercase) Pastes the buffer contents to the line above the current one.
  4. Lines deleted with dd also end up in the buffer and can be pasted.
  5. Words deleted with dw also end up in the buffer and can be pasted.

Advanced Cut and Paste

  1. There are 26 lettered buffers, labeled from a to z (lowercase), in addition to the usual "clipboard" one.
  2. Lettered buffers are accessed with the " double quote.
    Example: "a3yy yanks three lines into the a buffer starting with the current one.
    Example: "bp pastes the contents of buffer b to the line under the current one.

Going to a Line or Column

  1. Type a number followed by G (uppercase) to go to that line number.
    Example: 24G goes to line 24.
    Example: G goes to the last line of the buffer.
  2. Type a number followed by | (pipe) to go to that column in the current line.
    Example: 40| goes to column 40.

Repeat the Last Action

  1. Use . (period) to repeat the last action.
    Example: If you hit i to insert, then type "hello world" followed by the Esc key to enter command mode, then move to another line and hit . to repeat, the words "hello world" will appear before the current cursor position.

Search for a String

  1. Use / (foward slash) followed by a string to search for that string.
    Example: /foobar would find the first occurrence of foobar after the cursor position. It would also find, for example, something like foobariciousness.
  2. After the first occurrence of the string is found, use n (lowercase) to find the next occurrence. Continue hitting n as needed.
  3. Use N (uppercase) to find the previous occurrence of the string.
  4. Use ? (question mark) followed by a string to search backwards through the file for that string.

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


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