Skip to content

Instantly share code, notes, and snippets.

@pfmoore
Created April 3, 2013 13:54
Show Gist options
  • Save pfmoore/5301385 to your computer and use it in GitHub Desktop.
Save pfmoore/5301385 to your computer and use it in GitHub Desktop.
Vim script/function to pipe selection through a command (or run it as Vim script)
function! ExecRange(cmd) range
let l:old_a = @a
exec a:firstline . ',' . a:lastline . 'yank a'
if a:cmd == ''
exec @a
else
echo system(a:cmd, @a)
endif
let @a = l:old_a
endfunction
command! -nargs=* -range=% ExecRange <line1>,<line2>call ExecRange(<q-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment