Skip to content

Instantly share code, notes, and snippets.

@brooth
Created December 10, 2016 21:43
Show Gist options
  • Save brooth/5385ec64848614b1ba5f66b1337fd61b to your computer and use it in GitHub Desktop.
Save brooth/5385ec64848614b1ba5f66b1337fd61b to your computer and use it in GitHub Desktop.
" 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