Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selectable list of occurrences of searched word in current file.

Tags:

vim

search

You can use the following to get a list of matches in a file.

:g/<MATCH_THIS>/p

Is there a way to make this list selectable similar to the Ag.vim plugin?

Files containing the search term will be listed in the split window, along with the line number of the occurrence, once for each occurrence. [Enter] on a line in this window will open the file, and place the cursor on the matching line.

like image 450
Sten Kin Avatar asked Jan 28 '26 08:01

Sten Kin


1 Answers

:vimgrep/pattern/g %

Or maybe something like this:

nnoremap <leader>/ :vimgrep/<c-r>//g %<cr>:copen<cr>

Vimcast did a nice episode on this topic: Search multiple files with :vimgrep

For more help see:

:h :vimgrep
:h :caddexpr
like image 192
Peter Rincker Avatar answered Jan 31 '26 16:01

Peter Rincker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!