# Calling vimgrep from a comand

I'm trying to create a command that would accept arguments, and then call vimgrep with those arguments and display the quickfix window. I set up my command like

command! -nargs=* Vsearch :call <SID>VimGrepSeach(<q-args>)


and my <SID>VimGrepSearch is defined by:

function <SID>VimGrepSearch(query)
execute "normal! q:vimgrep /\\v" . a:query . '\g' escape('**/*', ' \')
endfunction


This will search all of the current directory and display the results in a quickfix window, if the equivalent is ran directly from command mode.

However, when I run this as a command, I get the quickfix quickly popping up, but then it's immediately hidden. What's going on here? Why does the quickfix window appear and then hide, and how can I have it stay open?

• Why are you using q:? That opens the command window. Try just execute "vimgrep /\\v" ... and then copen on the line below. – D. Ben Knoble Jan 26 '20 at 6:18
• @D.BenKnoble that gives me a "can't have multi follow a multi" because it's complaining about the path expansion **/*. – SalmonKiller Jan 26 '20 at 6:30
• To be clear, I’m saying don’t change anything except to remove the normal! q:... that shouldnt give you any new errors – D. Ben Knoble Jan 26 '20 at 14:33
• Actually, i think \g should be /g – D. Ben Knoble Jan 26 '20 at 14:39
• Yeah putting it all together: execute 'vimgrep /\v' . a:query . '/g **/*' followed by copen. @D.BenKnoble, you got all of those, you should turn them into an answer. – filbranden Jan 26 '20 at 16:36

execute 'vimgrep /\v' . a:query . '/g **/*'

command -nargs=* Vsearch vimgrep /\v<args>/g **/* | copen