Is it possible to pipe an unsaved buffer to an external command and then replace the buffer by the command’s output?
Asked
Active
Viewed 623 times
2 Answers
11
You can use the "filter" command,:!, which like most commands can be prefixed with a range:
:{range}!cmd
If you prefix this with a range, it will pipe those lines to the command's stdin, and replace those lines with the program's output. In this case you want to use % as the range, which means the entire buffer. For example:
:%!sort
You can find the Vim documentation with :help :range!.
Martin Tournoij
- 62,054
- 25
- 192
- 271
1
Yes that should be possible. One possibility: the system() function takes as optional argument the input to be used for the external command.
Christian Brabandt
- 25,820
- 1
- 52
- 77
:%!sqlformat --reindent --keywords upper --identifiers lower -– Eldamir May 18 '18 at 06:47