Skip to content

Instantly share code, notes, and snippets.

@mhinz
Last active August 8, 2020 07:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinz/1d62b803d328f83551e15c97a4b57868 to your computer and use it in GitHub Desktop.
Save mhinz/1d62b803d328f83551e15c97a4b57868 to your computer and use it in GitHub Desktop.
"
" usage: :Vimgrep /foo/ **
"
function! s:exit_handler(id) dict abort
execute 'cfile' self.tempfile
copen
endfunction
function! s:vimgrep(args) abort
let tempfile = tempname()
let commands = [ 'noautocmd vimgrep '. a:args ]
let commands += [ 'let matches = map(getqflist(), "printf(\"%s:%d:%d:%s\", bufname(v:val.bufnr), v:val.lnum, v:val.col, v:val.text)")' ]
let commands += [ 'call writefile(matches, "'. tempfile .'")' ]
let commands += [ 'quitall!' ]
let cmd = join(map(commands, '"+".shellescape(v:val)'))
if has('nvim')
call jobstart('nvim '. cmd, {
\ 'on_exit': function('s:exit_handler'),
\ 'tempfile': tempfile,
\ })
else
echomsg 'job_start() implementation missing'
endif
endfunction
command! -nargs=* -bang Vimgrep call s:vimgrep('<args>')
@bohrshaw
Copy link

call jobstart('nvim '. cmd, {

How about using nvim -u NONE.

@idbrii
Copy link

idbrii commented Nov 17, 2016

Using nvim -u NONE would mean that your magic, smartcase, ignorecase, gdefault, and other text matching settings would be ignored.

However, you may want to add a dummy file argument so if vim startup plugins (like vim-startify) check for args() that they find something and don't activate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment