vim增加格式化功能

来源:互联网 发布:北京快道网络 董事长 编辑:程序博客网 时间:2024/06/02 03:56

使用python格式化json:

:%!python -m json.tool

只要安装了python就可以调用这个命令实现json的格式化

注意:当有汉字的时候会出现汉字编码问题,解决办法是修改tool.py, 在main中的json.dump添加一个参数ensure_ascii=False

使用jdaddy.vim格式化json:

安装:
使用vundle添加

Plugin 'https://github.com/tpope/vim-jdaddy.git'
  • aj provides a text object for the outermost JSON object, array, string, number, or keyword.
  • gqaj “pretty prints” (wraps/indents/sorts keys/otherwise cleans up) the JSON construct under the cursor.
  • gwaj takes the JSON object on the clipboard and extends it into the JSON object under the cursor.
    There are also ij variants that target innermost rather than outermost JSON construct.

格式化xml

:%!xmllint --format -

需要在操作系统中安装xmllint程序,保证命令行可以调用。

原创粉丝点击