Skip to content
This repository
tree: 1563771179
Fetching contributors…

Cannot retrieve contributors at this time

file 39 lines (30 sloc) 1.616 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<h3 id="basic-navigation">Basic Navigation</h3>

<h4>Problem</h4>

<p>You want to move around inside a file.</p>

<h4>Solution</h4>

<p>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:</p>

<table>
  <tr><th>Key</th> <th>Movement</th></tr>
  <tr><td><kbd>h</kbd></td> <td>Left</td></tr>
  <tr><td><kbd>l</kbd></td> <td>Right</td></tr>
  <tr><td><kbd>k</kbd></td> <td>Up a line</td></tr>
  <tr><td><kbd>j</kbd></td> <td>Down a line</td></tr>
  <tr><td><kbd>0</kbd></td> <td>Start of line</td></tr>
  <tr><td><kbd>^</kbd></td> <td>First character of line</td><tr>
  <tr><td><kbd>$</kbd></td> <td>End of line</td></tr>
</table>

<h4>Discussion</h4>

<p>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.</p>

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

<p>Once you've become used to these keys, take a look at <i>motions</i> and
<i>text objects</i> in <a href="#selecting-text-with-motions">Selecting Text
  with Motions</a> to make the humble combination of <kbd>h</kbd>,
<kbd>l</kbd>, <kbd>k</kbd>, and <kbd>j</kbd> more powerful still.</p>
Something went wrong with that request. Please try again.