Vim – Capturing Output from Commands

One of the most useful things about Vim is its command-line mode. Using comamnd-line mode one can run external commands and capture the output and apply it to the buffer.

The external command is able to take text from the buffer, process it and replace the text.

Find checksum of lines of text

 :1,4 ! md5
 :% ! md5
              

Reformat JSON using jq

  :% ! jq .
              

One can also run an external command and have its output added to the current buffer.

Get list of files and insert into current buffer

  :. ! ls -latr
              

Capture output of a `curl` command and insert it into the current buffer

For example if one wants to insert the output from a curl command at the current line, one can do something like the following

  :. ! curl -s https://codeismandatory.com/about.html
  :. ! curl -s https://loripsum.net/api/1/plaintext
              

For more information, see the Vim help :he filter and :he :.