Format/Pretty-print JSON

3 Points

justyns justyns

10 years ago

When you press =j, the current buffer is auto-formatted using python's json library.

" Somewhere in .vimrc
nnoremap =j :%!python -m json.tool<CR>

garnerh42

garnerh42 10 years ago

Wish there was a way to change the indent. But still useful!

yang-ling

yang-ling 10 years ago

I suggest a vim plugin vim-jsbeautify: https://github.com/maksimr/vim-jsbeautify.

Just set json filetype to javascript and execute :call JsBeautify()