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.
Комментарии
Отправить комментарий