Vi For Smarties
Cut and Paste
- 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.
- p (lowercase) pastes the buffer
contents to the line under the current one.
- P (uppercase) Pastes the buffer
contents to the line above the current one.
- Lines deleted with dd also end up in the buffer and
can be pasted.
- Words deleted with dw also end up in the buffer and
can be pasted.
Advanced Cut and Paste
- There are 26 lettered buffers, labeled from a to
z (lowercase), in addition to the usual
- Lettered buffers are accessed with the " double
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
- 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.
- 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
- 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
Search for a String
- 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.
- After the first occurrence of the string is found, use
n (lowercase) to find the next occurrence. Continue
hitting n as needed.
- Use N (uppercase) to find the previous occurrence of
- 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
All rights reserved.