Hacker News new | ask | show | jobs
by NikkiA 2527 days ago
vim: use :%!cmd to pipe the current buffer into a command, and replace the buffer with the output from the cmd

vim: use :w !cmd to pipe the current buffer into a command but display the output from the cmd to screen and discard it afterwards

vim: use :r !cmd to read the output from the command and insert it into the current buffer

All of the :! and :r and :w commands that deal with a shell can also be passed the filename for the current buffer with %, eg:

":r !md5sum %" will execute md5sum with the filename of the current file (if it is unsaved, it will use the on-disk version, obviously) then pull the output checksum into the current buffer at the cursor position

1 comments

Emacs equivalents are (by default) mapped to M-! and M-| with/without prefix arguments (so C-u / M-<num> etc)