I am trying to set up the Node.js version of js-beautify as an equalprg
command when I am editing a JavaScript file, so that the Vim =
indent commands reflow my JavaScript at the same time.
Initially, I tried this:
autocmd FileType javascript setlocal equalprg=js-beautify -f -
(the -f -
is necessary because js-beautify otherwise doesn't read from stdin).
However, that fails with an error like this when I open a JavaScript file:
Error detected while processing FileType Auto commands for "javascript":
E518: Unknown option: -f
So then I tried adding surrounding quotes:
autocmd FileType javascript setlocal equalprg="js-beautify -f -"
That seems to work (JavaScript files open without error), but then 1G=G (or any other = command) seems to work in exactly the same way as the standard vim behaviour, and it appears it's not set up correctly - if I type :set equalprg
, I see:
equalprg=
If I remove the -f -
, the equalprg
is set, but it doesn't work, because js-beautify tries to read from a file:
Must define at least one file.
Run `js-beautify -h` for help.
How can pass these command-line options into js-beautify as part of setting equalprg?
Note I am aware that I could use the js-beautify vim plugin, but I'm trying not to overwhelm my vim setup with plugins, and instead setup the standard vim =
keymapping.