Indent JSON on save in Vim

Indent JSON on save in Vim

Im using elzrvim-json for JSON, which works very nicely. ggG indents JSON, and doesnt destroy my buffer if it contains invalid JSON. Is there a way that I can run ggG on save, but only for JSON files

I guess that you are looking for autocmd: :autocmd BufWritePre .json :normal ggG You can add this line to your vimrc and ggG will be applied to every file matching the .json pattern on save. Alternatively, you can use python -m json.tool to indent your JSON file: :autocmd BufWritePre .json execute python -m json.tool w This command will lint you code using an external command python -m json.tool and save it to the current buffer w.

Комментарии

Популярные сообщения из этого блога

Skipping acquire of configured file 'contrib/binary-i386/Packages' as repository … doesn't support architecture 'i386'

FillChar and StringOfChar under Delphi 10.2 for Win64 Release Target

Python Selenium - How to configure a client certificate file while initializing PhantomJS driver instance