How to fix JSON indentation in vim?

前端 未结 8 1288
粉色の甜心
粉色の甜心 2020-12-29 03:55

In vim, the default indentation for JSON is:

{
    \"employees\": [
    { \"firstName\":\"John\" , \"lastName\":\"Doe\" }, 
    { \"firstName\":\"Anna\" , \"         


        
相关标签:
8条回答
  • 2020-12-29 04:28

    Easier way is to just external command as a filter for a selection. e.g.

    1. Make a selection
    2. Type :!python -m json.tool
    0 讨论(0)
  • Add this statement to /etc/vim/vimrc:

    autocmd Filetype json setlocal ts=2 sw=2 expandtab
    

    It will force json presentation with 2 spaces tab, besides defining tab behaviour for such file.

    0 讨论(0)
提交回复
热议问题