在 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
的东西但仅限于选定的行。
最佳答案
指定行号应该有效。例如:
:5!python -m json.tool
或者如果它需要多行:
:4,6!python -m json.tool
关于JSON 格式仅包含 vim 中文件的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49797548/