Created
December 10, 2016 21:43
-
-
Save brooth/5385ec64848614b1ba5f66b1337fd61b 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
" ReplaceInFiles | |
function! ReplaceInFiles(o, n) | |
exec "Ag '" . a:o . "'" | |
if empty(getqflist()) | |
return | |
endif | |
let l:c = "%s/" . escape(a:o, '\') . "/" . escape(a:n, '\') . "/g" | |
let l:p = input('additinal params? (q=quit) :' . l:c) | |
if l:p == "q" | |
exec "bd %" | |
return | |
endif | |
exec "call QuickFixDoAll(\"" . l:c . l:p . "\")" | |
endfunction | |
function! ReplaceInFilesExact(o, n) | |
exec "Ag '\\b" . a:o . "\\b'" | |
if empty(getqflist()) | |
return | |
endif | |
let l:c = "%s/\\\\<" . escape(a:o, '\') . "\\\\>/" . escape(a:n, '\') . "/g" | |
let l:p = input('additinal params? (q=quit) :' . l:c) | |
if l:p == "q" | |
exec "bd %" | |
return | |
endif | |
exec "call QuickFixDoAll(\"" . l:c . l:p . "\")" | |
endfunction | |
" QuickFixDoAll | |
function! QuickFixDoAll(command) | |
if empty(getqflist()) | |
return | |
endif | |
exec "only" | |
let s:prev_val = "" | |
for d in getqflist() | |
let s:curr_val = bufname(d.bufnr) | |
if (s:curr_val != s:prev_val) | |
exec "edit " . s:curr_val | |
exec a:command | |
exec "write" | |
endif | |
let s:prev_val = s:curr_val | |
endfor | |
"exec "quit" | |
endfunction | |
command! -nargs=+ QuickFixDoAll call QuickFixDoAll(<f-args>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment