vim Movement Navigating to the beginning of a specific word


When editing text, a common task is to navigate to a particular word on the screen. In these examples we explore how we can navigate to the word updated. For the sake of consistency across the examples, we aim to land on the first letter of the word.

Mid-screen jump

enter image description here

This approach is quick, using only 3 keystrokes. The disadvantage however, is that it is not very general, as it's not common for our target line to happen to lie right on the middle of the screen. Still, it is a useful motion when making less granular movements.

Using a count

enter image description here

At first glance, this may appear to be a step back from the first approach because of the number of keystrokes. But since we use a count here instead of M, it is more flexible. We can quickly identify the correct count to use if relativenumber is enabled. To move to the target word, using f in combination with ; can be surprisingly effective - and certainly better than repeatedly pressing w. If you overshoot your target with ;, you can go backwards with ,.

Explicit search

enter image description here

Navigating via / can be very powerful. We can often jump directly to our target word by typing it out. Here we type out only the first two characters in the hope that it uniquely matches our word. Unfortunately, there are multiple matches, but we can quickly jump to the next match with n.

Implicit search

enter image description here

In some cases, it may be more efficient to jump near our target rather than aiming to go directly to it. Here we observe that there is an infrequently occurring letter, y, right next to the target. We can add a Space to our search term to decrease the chances that we hit some other y character along the way. This can also be used to great effect with f{char}, as in the example Using a count.