We learned about modes in the fundamentals chapter. In Vim, basic navigation is performed in normal mode, which you can get to from (almost) any situation by hitting the Esc key.
The most basic cursor movements (known as motions in Vim) are those used to move the cursor in small increments within a buffer. Most Vim distributions also support using the arrow keys for simple cursor movements, but it is good practice to ignore the arrows and get used to using these:
Command | Action |
---|---|
h | cursor N chars to the left |
l | cursor N chars to the right |
j | cursor N lines downward |
k | cursor N lines upward |
Moving the cursor
As a simple demo of basic cursor movements, we can start from the following buffer:
Hitting the j key moves the cursor down one line, as described above:
Using Counts
Now, suppose you want to move the cursor 4 columns to the right. One option is to type l 4 times, but Vim provides a better way, called counts.
Vim motions accept a count, which precedes the motion and specifies how many times to repeat the motion, following the basic pattern:
[count][motion]
So, rather than hitting l l l l, one can simply type 4l:
Note that the default count is 1, allowing the count to be omitted as in the first example.