Most editing and movement commands are single letters and are almost always the first letter of what they do. For example, to insert text
at your current
The capital letter of each command has a similar behavior. Use
Real words are those terminated by whitespaces (space, tab, newline). Assume we wanted to move across the
phrase ‘static-free bag’. If we start on the ‘s’, pressing
Movement in
Movement up and down is not quite as intuitive. One of the two remaining characters (j and k) will move us up and the other will move us down. But which one moves in which direction? Unfortunately, I don’t have a very sophisticated way of remembering. If you look at the two letters physically, maybe it helps. If you imagine a line running through the middle of these characters, then you see that j hangs down below that line. Therefore, use j to move down. On the other hand, k sticks up above the middle, so we use k to move up. However, in most cases, the arrow keys will work, so you won’t need to remember. But it is nice to know them, as you can then leave your fingers on the keyboard.
As I mentioned, some keyboard types will allow you to use the arrow keys. However, you might be surprised by their behavior in input mode. This is especially true if you are used to a word processor where the arrow and other movement keys are the same all the time. The problem lies in the fact that most keyboards actually send more than one character to indicate something like a left-arrow or page-up key. The first of these is normally an escape (Esc). When you press one of these characters in input mode, the Esc is interpreted as your wish to leave input mode.
If we want to move to the first character on a line, we press
We can also take advantage of the fact that vi can count as well as combine movement with this ability to count.
By pressing a number before the movement command, vi will behave as if we had pressed the movement key
that many times. For example,
If we want to move to a particular line we input the number and G. So, to move to line 43, we would press 42G, kind of
like 42-Go! If instead of
As you might have guessed, we can also use these commands in conjunction with the movement keys (all except