直接使用
vim打開json數(shù)據(jù),命令行模式下
:%!python3 -m json.tool
% 表示針對(duì)全部的行范圍,用 ! 調(diào)用外部命令
使用快捷鍵
可以在~/.vimrc增加快捷鍵
map <F4> :%!python -m json.tool<CR>
按F4即可
中文顯示為unicode解決方案
可以在~/.vimrc增加
command! Jsonf :execute '%!python -m json.tool'
\ | :execute '%!python -c "import re,sys;sys.stdout.write(re.sub(r\"\\\u[0-9a-f]{4}\", lambda m:m.group().decode(\"unicode_escape\").encode(\"utf-8\"), sys.stdin.read()))"'
注意是python2環(huán)境下才可以