CSC 101 Winter 2008

Vim Operations (courtesy Dr. O'Gorman)

Updates

Contents

Basic Operation

Vim has three main modes. Four if you count "insert" and "replace" as different.

Insert Mode

Normal Mode

Quitting

Add Text

From normal mode, enter one of the following commands (just a single letter). Choose the command according to where you want the text to go, relative to the position of the cursor (which is usually sitting on one of the characters in your document.

The command will put you in insert mode, and allow you to type new text until you leave insert mode (by pressing <Esc>). To begin with, you may want to just learn the first two. I mostly use the "i" command. That works for me everywhere except at the end of a line. For that, I use "a" or "A". You can do everything with just "i" and "A".

Delete Text (small amounts)

From normal mode, enter one of the following commands. Choose the command according to how much text you want to delete:

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).

Delete Text (larger amounts)

Some of these commands can delete a lot of text. If it's too much, see the Oops topic.

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).

Oops.

Indent

These commands will work on multiple lines if you preceed them by a number.

Move the cursor (navigate through your document)

The cursor keys on the keyboard almost always work. The mouse may work if you're actually using gvim instead of vim. Power users can do more work faster without a mouse, but the choice of what to learn is up to you.

The commands below can all be used with the “d” command to delete all the text that the command moves over. This is why “d1G” deletes to the beginning of the file (line 1), and so on.

In addition, there are commands for moving larger distances than may be otherwise convenient.

Copy and Paste Text

There is a “cut register” which can be used for cut-and-paste operations. There are actually 27 of these, but this will just talk about the default cut register.

You can put the contents of the “cut register” back into the document with the “p” and “P” commands. kk

You can paste more than once to make multiple copies.

Work with Files

Very important. These are all ex-commands so they start with a colon. Like all ex-commands, you have to press <enter> before the command is executed.

Search for Text

Repeating Commands

You can put a number in front of most vim commands, and this will have some effect on the command. Examples:

Split the Screen

You can split the screen horizontally, vertically, or both into parts called windows. These are mostly ex-commands, so they start with a colon (:) and require the <enter> key. Once they're open, you use normal-mode commands to manipulate the windows or switch among them. Here are the basics.

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.