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('**/*', ' \')

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?

  • 1
    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
    Commented Jan 26, 2020 at 6:18
  • @D.BenKnoble that gives me a "can't have multi follow a multi" because it's complaining about the path expansion **/*. Commented Jan 26, 2020 at 6:30
  • 1
    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
    Commented Jan 26, 2020 at 14:33
  • 1
    Actually, i think \g should be /g
    – D. Ben Knoble
    Commented Jan 26, 2020 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
    Commented Jan 26, 2020 at 16:36

1 Answer 1


The function should just be

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

Or you could do this with the command:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.