This document was last modified on 11 Jan 2008.
These entries are roughly in the order I expect you'll need them.
Vim has three main modes. Four if you count "insert" and "replace" as different.
This means that the editor will behave differently depending on the mode it is in
The modes are “normal”, “insert/replace” and “visual”
Normal mode allows you to enter many commands, to modify text, move it around, save it, and so on.
Insert and replace modes are for placing text in your document.
Visual mode is for special operations on blocks of text.
To get into insert mode, position the cursor where you want to do the inserting, and use an insert command ("i", "I", "A", "a", "o", and "O" are possible choices that I use a lot). See Add Text.
This is the mode for adding stuff to a document, so you'll spend a lot of time here, particularly at the beginning.
Because you can also do some other simple editing chores, beginners tend to stay here all the time, and not learn that there are good reasons to get back to "normal" mode. In plain gvim you might just forget that normal mode even exists, at least until you want to do some of the other stuff.
If you're using plain vim, you'll need to get to normal mode just to do basic file operations. The way out is the "Escape" key, whose key cap usually reads "Esc" and is in the upper left corner of the keyboard, perhaps next to the function keys.
You can save changes and quit the current window with ":wq", or with "ZZ".
If you have split the screen, these only close one window at a time.
At the beginning of the line (but after any beginning whitespace): enter "I"
At the end of the line: enter "A"
In a new line below the current line: enter "o"
The character under the cursor: “x”
The word after the cursor: “dw”
Everything to the end of the line containing the cursor: “D” or “d$”
Whatever you delete in this way is saved in a “cut register”, and can be put back in the document (see "Cut and Paste Text" below).
Some of these commands can delete a lot of text. If it's too much, see the Oops topic.
Multiple lines: enter a number before the “dd”. That's a line count.
To the end of the file: “dG”
To the beginning of the file: “d1G”
You'll notice the “d” keeps showing up.
Whatever you delete in this way is saved in a “cut register”, and can be put back in the document (see "Cut and Paste Text" below).
These commands will work on multiple lines if you preceed them by a number.
Add one “shiftwidth” of indentation to the current line: “>>”.
Remove one &dlquo;shiftwidth” of indentation from the current line: “<<”.
Add one “shiftwidth” of indentation to the rest of the document: &dlquo;>G”.
Center the current line (assuming 80 columns total): ":ce
80<enter>".
In addition, there are commands for moving larger distances than may be otherwise convenient.
To the left margin: “0” (zero)
To the beginning of the line: “^” (not control, just the shifted 6)
To the top line of the screen: “H”
To the middle of the screen: “M”
To the last line of the screen: “L”
To a specific line: <line number>”G”
Forward (down) a screen-height: “^F”
Back (up) a screen-height: “^B”
Down (forward) half a screen-height: “^D”
Up (back) half a screen-height: “^U”
One character up, down, right or left: cursor keys
What you delete from the document is actually "cut" into the cut register.
You can copy text into the cut register (without deleting it from the document) with the "y" (yank) commands that work much like the "d" (delete) commands without actually deleting. For instance:
yy
to yank the current line.
12yy
to yank the next 12 lines.
You can paste more than once to make multiple copies.
Search forward for text: “/”<text><enter> Like “/myvar” This will be shown on the bottom line
Search backward for text: “?”<text><enter> Like “?myvar” This will be shown on the bottom line
Find a particular character in the current line to the left of the cursor: “F”<char>
Find a particular character in the current line to the right of the cursor: “f”<char>
Find a character in the current line, but stop the cursor just before reaching it: “T” and “t”
:sp
splits the current window (horizontally) so both windows are looking
at the same file.
:vsp
splits the current window (vertically) so both windows are looking
at the same file.
:sp filename
splits the current window (horizontally) so the new window
is looking at filename.
:vsp filename
splits the current window (vertically) so the new window
is looking at filename.
^w^w
Cycle to the next window. This one is not an
ex-command; it's two control-w characters.
^wo
or ^w^o
Close all but the current window (think "only").
There are a LOT more ^w-commands. You can do just fine with these, however.
You write files and close parts of the screen with the same commands (:wq)(:w)(:q) that worked when the screen had
only one part. They affect the part of the screen that the cursor is in. When the last one is closed, vim quits.