Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Qdo and Qargs command used for replaceAll
" ============================================================================
" Description: Add Qdo and Qargs command used for replaceAll
" Author: Qiming Zhao <chemzqm@gmail.com>
" Licence: Vim licence
" Version: 0.1
" Last Modified: December 31, 2015
" ============================================================================
if exists('did_qdo_loaded') || v:version < 700
finish
endif
let did_qdo_loaded = 1
function! s:Qdo(bang, command)
execute 'UniteClose'
if exists('w:quickfix_title')
let in_quickfix_window = 1
cclose
else
let in_quickfix_window = 0
endif
arglocal
exe 'args '.s:QuickfixFilenames()
exe 'argdo'.a:bang.' '.a:command
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
command! -nargs=1 -bang Qdo call s:Qdo(<q-bang>, <q-args>)
command! -nargs=0 -bar Qargs execute 'args' s:QuickfixFilenames()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment