在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>
Run Code Online (Sandbox Code Playgroud)
我想将标记的行更改为
{
"bla":[
1,
2,
3
],
"yes":false
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似:%!python -m json.tool但仅适用于选定行的东西.
小智 11
指定行号应该有效.例如:
:5!python -m json.tool
Run Code Online (Sandbox Code Playgroud)
或者如果它需要多行:
:4,6!python -m json.tool
Run Code Online (Sandbox Code Playgroud)