Is there any way to use regular expression for movement in vim. For example, I want to move my cursor to the first occurrence of the pattern abc. So can I do something analogous to fa but now a character replaced by a pattern? And can I use regular expressions with t and f command?

  • 1
    You can search with regex and the cursor will move to the start of the regex. Is this what you mean? – Sardathrion - against SE abuse Aug 20 '12 at 7:10

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").
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.