What is VIM?

Vim is a MODAL text editor that you can use without a pointing device.

Why Use VIM?

Using a pointing device - a touch-pad or mouse - is more intuitive and so easier to begin with. But having to switch between pointing/selecting and typing adds an overhead. This over-head is probably not significant when you are first learning to code, because most of your time will be spent working out what to type, not typing. As you get more proficient, though, you will want to be able to move text around as fast as possible, as soon as you realise where it needs to go or how it needs to change. In general, there is no doubt that being able to do everything from the keyboard will make you much faster.

Learning VIM

Learning VIM is a lot like learning to touch-type when you're already "fast enough" with two fingers. It can be hard to make yourself do it the 'right' way and, at first at least, you'll actually be slower, not faster. There is a bit of an over-head in using the VIM commands until you're somewhat proficient.

One way to overcome this barrier, to some extent, is to apply the vim key-bindings to an editor that you're already familiar with and use it as an addition to what you already do.

See where it might be able to make you faster.

Then, play around with the native version.

Consider the relative size of the two programs.


The most important thing to realise about VIM is that there are several different modes that it can be in and the effect of pressing keys is different depending on which mode it's in. This is necessary so that we can use the same keys for entering text or navigating and editing.

The current mode is always displayed at the bottom of the editor window.

VIM starts off in NORMAL MODE and this mode is used for navigating the document. Pressing keys won't immediately start entering text as you might expect. Instead

Moving Around

I don't think this is too crazy - and it makes sense of what we're trying to do, which is basically to achieve all possible editing tasks, in as few key-presses as possible, those keys being as close to the middle of the keyboard as possible.

So, we can use the arrow-keys to move around, but we can also use the keys h, j, k, l to do the same. This is precisely so that we don't have to move our hands from a normal typing position to be able to move around our files.

It wouldn't be very efficient to move one place at a time wherever we wanted to go, but how are we going to scroll or click on a new place without using a mouse? We're not. Instead there are keyboard shortcuts that will jump the cursor to a new place in the file.

There are lots of such key combinations and most vim tutorials start to explain at least some of them at this point.

Insert and Append

The most obvious thing you're going to want to do is add and remove text from a file.

The easiest way to do that is to put the editor into "Insert" mode, by pressing I - you should see the mode displayed at the bottom of the screen change to INSERT.

Undo and Re-do

In NORMAL mode, pressing u will undo the last action.

Saving and Quitting

In NORMAL mode, pressing : gives you a prompt at the bottom of the screen, where you can type file-commands.

Pressing q and return will try to quit the file. If there are unsaved changes, you won't be allowed to quit the file, but will instead be prompted to save.

E37: No write since last change (add ! to override)

To save your file, get to the : prompt and type w (followed by return)

vim tutor