Learning Vim: Day 1

Moving Around

Replacing the arrow keys

  1. Don't touch the arrow keys, at least for a while! (You have to drop the habit of using them hard, since your muscles are trained to reach for them.) They can be useful later, but for now avoid them.
  2. Instead of the arrow keys, use:
Keys to type What they do
h left-arrow
j down-arrow
k up-arrow
l right-arrow

Note: Many vim commands can take a number in front. xY will do the command Y x times. So, to go up 10 lines, type:
10k
Or to go back 8 characters, type:
8h

Paging up and down

Keys to type What they do
Ctrl-f page down
Ctrl-b page up

(Ctrl-f means hold down the control key while typing the key f.)
We can use mnemonics here to remember these commands better:
Ctrl-f goes forward in the file.
Ctrl-b goes backwards in the file.

Go directly to a line

Sometimes we want to just shoot directly to some line of text. For instance, if our programming language reports, "Syntax error on line 17," we want to go look at (and probably edit) that line.
Here's how to do that:

Keys to type What they do
xG goes directly to line x
G goes to the end of the file

The mnemonic to remember this command is that G means Go to a line!

Practice

Type 40 lines of text into practice.txt. (Remember, use vim practice.txt to edit the file, and use i to insert text.) It doesn't matter now what you type: nonsense will do!
Hit the esc key to go back to command mode.
Now use each of the above commands to move around the file.
Practice each one until you have some muscle memory for the command.