Commit 62664a6e authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Handle "$*" in Vim's &grepprg correctly

parent 87554bad
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -158,10 +158,17 @@ nmap <silent> th :set hlsearch!<CR>

" === GREPPING ===

function! s:greprep(string, ...)
	let replacements = {'\|': '|', '$*': join(a:000)}
	let rekeys = keys(replacements)
	call map(rekeys, {k, v -> escape(v, '\$*')})
	let regex = join(rekeys, '\|')
	return substitute(a:string, regex, {m -> replacements[m[0]]}, 'g')
endfunction

command! -bang -nargs=1 AsyncGrep
			\ exe 'AsyncRun<bang> -auto=grep'
			\ substitute(&grepprg, '\\|', '|', 'g')
			\ <q-args>
			\ <SID>greprep(&grepprg, <q-args>)

noremap <silent> S :AsyncGrep '\b<cword>\b'<CR>
vnoremap <silent> S ""y:exe 'AsyncGrep'