Re:Ask HN: What are some terminal tricks you wish you knew s...
by NikkiA on Sunday July 21, 2019 @05:46PM
(#20493870)
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
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