Using Regex in Vim movement

cursorregular expressionvim

Is there any way to use a regular expression for moving in Vim?

For example, I want to move my cursor to the first occurrence of the pattern abc.

Can I do something analogous to fa but replacing the character a with a pattern? And can I use regular expressions with the t and f commands?

Best Answer

As stated in a comment by Sardathrion, you can search to navigate. This is actually too useful in Vim to ignore. A few tips regarding search to navigate:

  • Use / to search forward, ? to search backward.
  • You may want to turn on incsearch so that Vim will jump to matches as you type. Hit Enter when you are at the location you want.
  • You may also want to turn on search highlight with hlsearch.
  • After arriving at the location you want, you can use nohlsearch to disable the highlight. It will be enabled again when you do the next search.
  • If you find yourself using lots of regex consider using \v ("very magic").