How do I pipe the contents of the current buffer to an external command and replace the contents of the buffer with the output from the command?
:! command to pipe the contents of the current buffer to a external command and replace the contents of the buffer with the output from the command. For example, to sort the contents of the current buffer, using the Unix sort command, you can use the following command: :%!sort To sort only lines 10-20, you can use the following command :10,20!sort Also, if you want to pipe a buffer to an external command but not put the results back in the buffer, you can use :w !sort The above command will pipe the entire buffer to the sort command. Note that the space between the ‘w’ and the ‘!’ is critical. To pipe only a range of lines, you can use :10,20w !sort The above command will pipe the lines 10-20 to the sort command. For more information, read :help :range! :help 10.
Related Questions
- How do I pipe the contents of the current buffer to an external command and replace the contents of the buffer with the output from the command?
- Should we replace the catalytic convertor with orginal parts or universal or just put on straight exhaust pipe?
- Why is the * necessary in the output of the emote command?