For example, if I want to run tidy on a file

r! tidy %

But I have to save the file beforehand. Is there any way around this?

2 Answers 2

:range! command

This will run an external command, pipe the lines specified in range to it and replace range with the output of the command.

As a special case, % as a range includes all lines in the buffer. (see help :%) So this should do what you want:

:%! tidy

@dan-j answer, as stated, replace the lines with the output. To run the file in a shell (without saving) use

:w command

e.g.: :w !tidy or :w !bash

and thanks @james at this discussion for the answer


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.