Not sure if this has been ask, if so I can't find it.
I want to run vimgrep to search for a pattern. I've been doing this. And when it find a match, it seems to open up the first file right away.
This is not what I want. I want the quickfix window to be open in horizontal pane split for me to navigate through the matches. This is my command in vimrc
command! -nargs=1 Ngrep vimgrep "<args>" **/*.md
vimgrep is Vim's built-in command for searching across multiple files. It's not so fast as external tools like ack and git-grep, but it has its uses. vimgrep uses Vim's built-in regex engine, so you can reuse the patterns that work with Vim's standard search command.
The quickfix and location lists provide a powerful way to navigate in Vim especially in the context of searching a file or project, and when inspecting errors. Essentially, they are lists of file locations with a built-in set of commands for navigating between them, and they can be populated in a variety of ways.
Add this snippet to your vimrc
to tell Vim to automatically open the location/quickfix window after :make
, :grep
, :lvimgrep
and friends if there are valid locations/errors:
augroup myvimrc
autocmd!
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
augroup END
If you don't want Vim to jump to the first match, use the j
flag:
:vimgrep /foo/j **/*.md
as explained in :help :vimgrep
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With