I want to select a block of text (for example, V%) and use the text as input to a shell command (for example, wc or pbcopy) – but I don’t want to alter the current buffer – I just want to see the output of the command (if any) then continue editing without any changes.
Typing V%!wc translates to :'<,'>!wc and switches the block of text for the output of the wc command.
How do you pipe a chunk of text to an arbitrary shell command without affecting the current buffer?
Select your block of text, then type these keys :w !sh
The whole thing should look like:
That’s it. Only took me 8 years to learn that one : )
note: typing : after selecting text produces :'<,’> a range indicating selection start and end.
Update 2016: This is really just one use of the generic:
Which basically lets you “send” arbitrary parts of your file to external commands and see the results in a temporary vi window without altering your buffer. Other useful examples would be:
I honestly find it more useful to alter the current buffer. This variety is simply: