由于vimscript的低效,vim在编辑很大的python文档的时候,换行要占用相当长的时间,以至于用户可以感到非常令人讨厌的延迟。下面是我在处理一个上千行的python文件的时候,使用profile功能记录的仅仅进行一次换行操作的时间结果。
FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
1 0.157815 GetPythonIndent()
2 0.023986 128_write_buffer()
636 0.017578 102_get_syn()
248 0.055931 0.017174 airline#highlighter#exec()
318 0.035959 0.015646 airline#highlighter#get_highlight()
...
于是我设计了插件:https://github.com/sillybun/autoformatpythonstatementgithub.com
在这个插件中我使用了C重写了python文件中的换行缩进功能,避免出现因为换行造成的延迟现象。
同时这个插件的本意是进行自动的整理代码:
比如你输入一行代码:
a=1+2
在输入回车后会自动的整理为:
a = 1 + 2
安装:
对于vim-plug:
Plug 'sillybun/autoformatpythonstatement', {'do': './install.sh'}
对于vundle:
Bundle 'sillybun/autoformatpythonstatement'
安装好后需要进入插件文件夹,运行:
./install.sh