Created
December 4, 2015 04:16
-
-
Save MarioRicalde/df16d9535acf0861c0ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" --------------------------------------------------------------------------------------------------- | |
" Search and Replace Functionality | |
" https://github.com/MarioRicalde/vim-qargs/tree/master/plugin | |
" :vimgrep /match/ ** | |
" :Qdo %s//replace/g | |
command! -nargs=0 -bar Qargs execute 'args ' . s:QuickfixFilenames() | |
command! -nargs=1 -complete=command -bang Qdo call s:Qdo(<q-bang>, <q-args>) | |
command! -nargs=1 -complete=command -bang Grep call s:Grep(<q-bang>, <q-args>) | |
" Mario's simple wrapper, so you can do: | |
" :vimgrep /match/ ** | |
" :Qdo %s//replace/g | |
function! s:Grep(bang, args) | |
let @/ = matchstr(a:args, "\\v[\/]\\zs.{-}\\ze[\/]") | |
call feedkeys(":let &hlsearch=1 \| echo \<CR>", 'n') | |
execute "vimgrep " . a:args | |
execute "copen" | |
endfunction | |
function! s:Qdo(bang, command) | |
if exists('w:quickfix_title') | |
let in_quickfix_window = 1 | |
cclose | |
else | |
let in_quickfix_window = 0 | |
endif | |
arglocal | |
exe 'args '.s:QuickfixFilenames() | |
" Ignore Auto Commands, this makes changes as fast as possible. | |
exe 'noautocmd argdo'.a:bang.' '.a:command. ' | update' | |
argglobal | |
if in_quickfix_window | |
copen | |
endif | |
endfunction | |
function! s:QuickfixFilenames() | |
" Building a hash ensures we get each buffer only once | |
let buffer_numbers = {} | |
for quickfix_item in getqflist() | |
let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr']) | |
endfor | |
return join(map(values(buffer_numbers), 'fnameescape(v:val)')) | |
endfunction | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment