Zet - How do I pipe the vim buffer through an external command, for example jq, prettier and cat?
How do I pipe the vim buffer through an external command, for example jq, prettier and cat?
Use :%!${cmd}
Example use jq to format buffer using correct indent
:%!jq --indent 4
If you want to format a selection, eg prettier just a few lines:
Select the lines using visual mode
:'<,'>!npx prettier --stdin-filename test.ts
'<,'> is provided by the visual select --stdin-filename test.ts is needed to give prettier context of what parser to use by using a fake ts filename here
If you want to pipe the buffer to an external command but not back into the buffer(eg. to cat so you can copy from ssh) use:
:w !cat
Basically you’re writing out to cat.
#vim #prettier