原文链接: 打造vim成为python IDE, 支持自动补全, 定义跳转, 按PEP8规范自动缩进和代码格式化
环境
1 2 3 4 5 6 7 8 9 10 11
| ➜ ~ cat /etc/redhat-release Fedora release 25 (Twenty Five) ➜ ~ vim --version | grep python +cryptv +linebreak -python +vreplace +cscope +lispindent +python3 +wildignore ➜ ~ vim --version | head -3 VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 28 2017 20:20:58) Included patches: 1-586 Compiled by kylin
|
依赖
1 2 3 4
| sudo dnf install python3-flake8 sudo ln -s /usr/bin/flake8-3 /usr/bin/flake8 sudo dnf install python3-autopep8 sudo dnf install python3-jedi
|
配置.vimrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Plugin 'davidhalter/jedi-vim' Plugin 'nvie/vim-flake8' Plugin 'Vimjas/vim-python-pep8-indent' Plugin 'tell-k/vim-autopep8' let g:pymode_python = 'python3' autocmd VimEnter *.py python3 sys.path.append('.') autocmd BufWritePost *.py call Flake8() "using flake8 as a python syntax checker let g:syntastic_python_checkers=['flake8'] let g:syntastic_python_flake8_args='--ignore=E501,E225' let g:autopep8_aggressive=2 let g:jedi#force_py_version=3 let g:jedi#smart_auto_mappings = 0
|
jedi用于代码自动补全, 定义跳转
flake8用于代码检查
pep8-indent用于自动缩进
autopep8用于代码按PEP8规范格式化
插件安装具体操作请见使用 vundle 管理 vim 插件
set smartindent
, 编写python代码时会使#
(注释)自动回退到行首
其他补充
自动安装配置vim请见
1
| https://github.com/shuhm-gh/oh-my-vim
|