Vim Recipes Basics Basic Navigation

Basic Navigation

Problem

You want to move around inside a file.

Solution

The traditional approach is to use the arrow keys to move up, down, left, and right. Vim supports that style of navigation but also offers a more efficient alternative:

Key Movement
h Left
l Right
k Up a line
j Down a line
0 Start of line
^ First character of line
$ End of line

Discussion

It is tempting to rely on old habits for something as basic as moving around in a file. Once you're used to The Vim Way, however, you'll find yourself much more efficient. One reason for this is that these keys are all located on the main keyboard, so you don't need to stretch to the arrow keys, hence breaking your flow.

Another benefit is that you can prefix these shortcuts with counts (as you can with many Vim commands) which specify how many times they should be executed. For instance, 2k moves up two lines.

Once you've become used to these keys, take a look at motions and text objects in Selecting Text with Motions to make the humble combination of h, l, k, and j more powerful still.