External Filter Tricks

!{motion}cmd โ€” let any Unix tool transform your text.

Keys: !

Vim's filter command !{motion} sends the text covered by motion as stdin to a shell command, replacing it with stdout. Sort, dedup, format, encode, decode โ€” any tool works.

Vim's filter operator (Normal-mode !) sends a chunk of the buffer through a shell command and replaces it with the result. Combined with Unix tools, you have unlimited transforms.

Sequence Effect
!!sort Sort current line through sort (no-op for one line, but legal)
!ipsort Sort the inner paragraph
!Gsort Sort from cursor to end of file
:%!sort Sort the whole file
:%!sort -u Sort + dedup
:%!jq . Pretty-print JSON in place
:%!python -m json.tool Same, with Python
:%!xmllint --format - Pretty-print XML
:%!fmt -w 80 Reflow to 80-column lines
:'<,'>!base64 Base64-encode the visual selection

Watch

See also: Shell Commands ({key::!})