One of Vim's super-powers is the breadth of commands available to move the cursor around a buffer. We will first look at some of the commands for moving the cursor (generally) horizontally. In many cases these are the most commonly-used commands, since they control cursor location while typing sentences or lines of code.
| Command | Action |
|---|---|
| f{char} | cursor to Nth occurrence of {char} to the right |
| F{char} | cursor to the Nth occurrence of {char} to the left |
| t{char} | cursor till before Nth occurrence of {char} to the right |
| T{char} | cursor till after Nth occurrence of {char} to the left |
| ; | repeat latest f, t, F or T N times |
| , | repeat latest f, t, F or T in opposite direction N times |
| & | repeat last :s |
Let's demonstrate these commands, using the following buffer:
First, lets jump to the first e using fe:
Note that the cursor moved directly on top of the character we were searching for, e.
f{char} also accepts a count, so let's jump to the 2nd e using 2fe:
The t{char} command is similar to f{char}, except instead of moving the cursor on top of the target, it moves the cursor up next to the target:
Like f{char}, t{char} also accepts a count:
Now, to demonstrate repeating a search, ; repeats the previous search:
, repeats the previous search but in the opposite direction:
Note that in this search we were moving up to the o. The previous search started from
the n in not, while the reverse search ended at the t.