vi: wicked cool stuff


1:0 The basic movement commands, h, j, k, and l, will get you anywhere you want to go. Here are some other commands that will help you move around quicker:

Many of these commands, when preceded with a number, will execute that command a number of times. 10G goes to the 10th line of a file, 15w moves 15 words forward, 5k moves 5 lines up.

1:1 You can stick up to 26 invisible bookmarks in your file to help you navigate around in it. The m command, followed by any letter, creates a mark which you can return to by using either the ' (single quote) or ` (back quote) command. Here are some examples of things you can do with marks.

Alas, when you quit or edit a new file, all the marks are lost.

1:2 You can replace existing text with new text in many various ways. All of these commands leave you in insert mode, except for the r command, which leaves you in command mode. Commands that change more than one character change things from the current character position wherever you specify.

1:3 You can cut and paste using command mode or colon commands. The command mode is simplest: simply delete some text, position the cursor at the new location, then put it back (see 0:5 for help on those commands). The same procedure may be followed for words (dw, 10dw, 5db, etc.) If you want to copy the text, leaving the original part intact, yank it, then put it as above. Another way to move or copy text uses marks (see 1:1). If you set a mark at the top (mark x), bottom (mark y), and destination (mark z), the command
will move the text between marks x and y after z. To copy the text without deleting it, use The ., ^, and $ characters have special meanings in colon commands that use marks. 1:4 You can use up to 26 named buffers (a through z) to store text that you have yanked or deleted. They are accessed using the " command. Marks (which also use the letters from a to z) can be used in conjunction with text buffers. Text which is stored in a buffer may be put into another file as long as you stay in the same vi session. For example, to add the first ten lines of file1 to the end of fileb, edit file1, then yank ten lines into buffer a (using "a10yy), then edit fileb using the colon command :efileb, then put the text from buffer a at the end of the file by typing G"ap.

1:5 The u command undoes the last edit command you executed. If you have performed several edits on one line and have not moved the cursor off of the line, you can restore it using the U command. There are ten numbered delete buffers which hold the ten most recently deleted blocks of text that are at least one full line long. Use the command "1P to insert the most recently deleted block of text above the current line. Use the . (dot) command (see 1:7) to insert successive blocks of deleted text.

1:6 The search commands (/ and ?) are very flexible, allowing you to search for patterns as well as exact works. These search patterns (called regular expressions) use special symbols (called metacharacters) to match different patterns:

After using a search command (/ or ?), you can find the next occurrence of the same pattern using the following commands. Other search commands are: 1:7 You can repeat your last editing command with the "." command. Changes, deletions, and insertions work with the "." command. Searches do not work with the "." command.

1:8 Here are some other colon commands you can use:

1:9 Always remember: it doesn't really matter if you pronounce it "vee-i" or "vi". It works the same. Every time.

Here endeth the lesson

vi evangelical series /
January 1995 (updated April 6, 1998)