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 linectrl-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:
Was this useful? Help us improve!
With your feedback, we can improve VimTricks. Click a link to vote:
You did not mention *, #, or ^L or ^R^W, so I will. Click on the string you want to search for, then press * or # to start a forward or reverse search using the current word! Pressing control L adds letters from the edited file to your search pattern while ^R^W adds the entire next trailing word. As you indicated ^g & ^t can be used to navigate before completing the search command.
Didn't work for me. Vim was just adding ^G and ^T after search pattern. So maybe this trick requires some customization. Although using 'n' to search forward and 'N' to search backwards helped.