跳至主要内容

Auto format files based on type in VIM

It would be really convenient to utilise the editor to auto-format some lengthy lines, e.g. a super long SQL retrieved from logging output; or a wrapped JSON literal captured in your browser. Luckily it's easy to achieve this in VIM - Firat, you'll need to install a few modules using `pip`, including `sqlparse` and `json.tool`. And then in the `filetype.vim` (or your own `vimrc`), include below commands: autocmd FileType xml setlocal equalprg=xmllint\ --format\ --recover\ -\ 5>/dev/null autocmd FileType json setlocal equalprg=python\ -m\ json.tool autocmd FileType sql setlocal equalprg=python\ -m\ sqlparse\ -a\ -s\ -

评论