JSON漂亮的格式只是vim

时间:2018-04-12 13:13:23

标签: json vim

在VIm中,有没有办法以“漂亮”格式打印文件中的JSON?

例如,拥有以下文件

# a comment
def my_func():
    pass

{"bla": [1, 2, 3], "yes": false}  # <--- pretty print this

# another comment
<foo>why do I mix everything in one file?</foo>
<bar>it's an example, dude</bar>

我想将标记的行更改为

{
   "bla":[
      1,
      2,
      3
   ],
   "yes":false
}

我正在寻找像:%!python -m json.tool这样的东西,但只针对选定的行。

1 个答案:

答案 0 :(得分:11)

指定行号应该有效。例如:

:5!python -m json.tool

如果它需要多行:

:4,6!python -m json.tool
相关问题