Something I've found useful in other editors is the ability to:
- take the selected text
- run an external command and pass the selection to its
stdin - take the external commands
stdoutand replace the current selection with it.
This way you can write useful text tools which operate on the selection using any language that can do basic io.
How can this be done with vim using the selection? ... a single character, word, paragraph... etc.
(Directly in the command line, or via a key binding?)
Note
Commands such as !sort work on the line-level, the reason I'm asking this question is because I would like to operate on the selection. (i.e., the text that would be removed if x was pressed).
sortcommand. – Cody Poll Feb 04 '15 at 16:24:sort? – Martin Tournoij Feb 04 '15 at 16:25!) behaves. If you want different behaviour, you'll have to code it manually (I can't find anything built-in for it), and that this is probably because most UNIX programs work on lines. – Martin Tournoij Feb 13 '15 at 09:58jq '.'can be used in place ofpython -m json.tool. Just saves a bit of typing, and it's a great CLI tool overall. – J.M. Janzen Oct 28 '19 at 21:28