Stay in Search Mode

3.8
(326)

You are probably already aware that you can search in Vim by typing / and entering a pattern. Typically you might search like so:

/some_pattern<CR>

Hitting <CR>, aka carriage return or “Enter”, immediately exits search mode. That means that refining the search patterns and running it again requires that you return to search mode using / followed by the up arrow to reenter the previous pattern. Then you can modify the pattern and try again. But there is a better way!

  • ctrl-g – Jumps to the next occurrence of the pattern, but keeps focus in the command line
  • ctrl-t – Jumps to the previous occurrence, but again keeps focus in your search

This allows for a search workflow that where you can see and page through the matches while modifying and refining your search pattern. Here’s a short screencast of these in action:

How useful was this tip?

Average rating 3.8 / 5. Vote count: 326

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

90 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

6 thoughts on “Stay in Search Mode”

  1. This doesn’t work in WindowsTerminal on WSL2 too. Whe pressing ctrl + g /ctrl + t I get ^G/^T right after my pattern.

Leave a reply

Your email address will not be published. Required fields are marked *