Format/Pretty-print JSON

3 Points

justyns justyns

9 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 9 years ago

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

yang-ling

yang-ling 9 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()