David542
David542

Reputation: 110203

Go to search result without having to press enter in vim

I would like for my cursor to automatically go to the search result after I stop typing. For example, I type in /new, after 100ms (or whatever the debounce/delay is), I'd like the cursor to automatically go to the first match (if it exists) rather than me having to constantly hit return with my pinkie, which gets a bit sore having to press return 100 times per day.

Is there a setting to do this in vim, or how could something like this be achieved if there is not? From vim's help for incsearch:

You still need to finish the search command with <Enter> to move the cursor to the match.

Upvotes: 6

Views: 1569

Answers (1)

doopNudles
doopNudles

Reputation: 705

First, important information:

When you are performing a search and incsearch is set, the current match will be highlighted as the highlight group IncSearch. If you also have hlsearch set, then the other non-current matches on your screen will also be highlighted, instead as the highlight group Search. For example, if you search for thing and the word thing appears three times on screen in your current file, the first match after your cursor will be the 'current match' and highlighted so. The other matches will be highlighted differently.

Now to answer your question

You can move between matches while searching without ending the search by pressing <Enter>. This is done with <C-G> and <C-T> (That's CTRL-G and CTRL-T). Reference :h /_ctrl-g and :h /_ctrl-t. This allows you to move through the file and see all the matches of the pattern you have already typed without actually ending the search. This also allows you to use <C-L> to add characters to the search. I'll let you look that one up (:h /_ctrl-l>).

Upvotes: 7

Related Questions