Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created August 13, 2012 08:29
Show Gist options
  • Save violetyk/3338246 to your computer and use it in GitHub Desktop.
Save violetyk/3338246 to your computer and use it in GitHub Desktop.
function! s:replace(...) range "{{{
if a:0 < 2
return
endif
let range = a:firstline . ',' . a:lastline
let tmp = @@
silent exec range . 'yank'
let text = @@
let @@ = tmp
let text = substitute(text, '\C\V' . escape(a:1, '\'), escape(a:2, '&~\'), 'g')
silent exec "normal! :". range . "change!\<CR>" . text . "."
endfunction "}}}
command! -nargs=+ -buffer -range Replace :<line1>,<line2>call s:replace(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment