python学习-vim插件安装,,centos7上自带


centos7上自带python2.7,我们需要优化一下python环境。

一、使用豆瓣源加速软件安装

pipinstall-iflask#使用-i选项mkdir~./pip&&vimpip.conf#修改pip的配置文件[global]index-url=https://pypi.douban.com/simple/

技术分享图片

二、修改.vimrc文件

主要增加一些配置选项,例如显示行号,一键执行等

vim.vimrc
setnocompatible"关闭与vi的兼容模式setnumber"显示行号setnowrap"不自动折行setshowmatch"显示匹配的括号setscrolloff=3"距离顶部和底部3行"setencoding=utf-8"编码setfenc=utf-8"编码setmouse=a"启用鼠标sethlsearch"搜索高亮syntaxon"语法高亮auBufNewFile,BufRead*.py\settabstop=4"tab宽度\setsofttabstop=4\setshiftwidth=4\settextwidth=79"行最大宽度\setexpandtab"tab替换为空格键\setautoindent"自动缩进\setfileformat=unix"保存文件格式setfoldmethod=indentsetfoldlevel=99map<F8>:callRunPython()<CR>func!RunPython()exec"W"if&filetype=='python'exec"!timepython2.7%"endifendfunc



一键F8执行效果


技术分享图片



三、配置vim插件管理vundle

Vundle 是 Vim bundle 的简称,使用git来管理vim插件,有了它,安装其它插件就方便很多。

创建目录

cd~mkdir.vimcd.vimmkdirbundle

进入目录,下载文件

gitclonehttps://github.com/VundleVim/Vundle.vim.git~/.vim/bundle/Vundle.vim

然后将下列配置放在.vimrc文件的开头:

setnocompatible"beiMproved,requiredfiletypeoff"required"settheruntimepathtoincludeVundleandinitializesetrtp+=~/.vim/bundle/Vundle.vimcallvundle#begin()"letVundlemanageVundle,requiredPlugin'VundleVim/Vundle.vim'"AllofyourPluginsmustbeaddedbeforethefollowinglinecallvundle#end()"requiredfiletypepluginindenton"required

如果想下载某个插件,比如自动缩进indentpython.vim插件,需要将

Plugin'vim-scripts/indentpython.vim'

置于callvundle#begin()和callvundle#end()之间,保存配置后在vim中执行

:PluginInstall

技术分享图片

技术分享图片

四、多窗口编辑



五、安装常用python插件

编程提示插件jedi-vim

pipinstalljedigitclone--recursivehttps://github.com/davidhalter/jedi-vim.git~/.vim/bundle/jedi-vim

技术分享图片


2.语法检查syntastic

gitclonehttps://github.com/vim-syntastic/syntastic.gitPlugin'vim-syntastic/syntastic'#.vimrc中增加

3.flak8代码风格检查

pipinstallflake8https://github.com/nvie/vim-flake8.gitPlugin'nvie/vim-flake8'#.vimrc中添加

按F7进行检查·

技术分享图片


4.添加树形目录

gitclonePlugin'scrooloose/nerdtree'#.vimrc中添加map<C-n>:NERDTreeToggle<CR>#.vimrc中添加使用Ctrl+n快捷键

技术分享图片


5.缩进显示 indentline

gitclonehttps://github.com/Yggdroot/indentLinePlugin'Yggdroot/indentLine'#vimrc中添加

技术分享图片


6.vim-autopep8自动格式化代码

pipinstallautopep8gitclonehttps://github.com/tell-k/vim-autopep8.gitPlugin'tell-k/vim-autopep8'#vimrc中添加autocmdFileTypepythonnoremap<buffer><F9>:callAutopep8()<CR>#使用快捷键F9

技术分享图片


7.auto-pairs自动补全括号和引号

gitclonePlugin'jiangmiao/auto-pairs'

8.ctrlp.vim搜索文件

在vim普通模式下搜索ctl+P即可

Plugin'kien/ctrlp.vim'

技术分享图片


最终,整个配置文件.vimrc如下所示:

setnocompatible"beiMproved,requiredfiletypeoff"required"settheruntimepathtoincludeVundleandinitializesetrtp+=~/.vim/bundle/Vundle.vimcallvundle#begin()"letVundlemanageVundle,requiredPlugin'VundleVim/Vundle.vim'Plugin'davidhalter/jedi-vim'Plugin'vim-syntastic/syntastic'Plugin'nvie/vim-flake8'Plugin'scrooloose/nerdtree'Plugin'Yggdroot/indentLine'Plugin'tell-k/vim-autopep8'Plugin'vim-scripts/indentpython.vim'Plugin'kien/ctrlp.vim'Plugin'jiangmiao/auto-pairs'"AllofyourPluginsmustbeaddedbeforethefollowinglinecallvundle#end()"requiredfiletypepluginindenton"requiredsetnocompatible"关闭与vi的兼容模式setnumber"显示行号setnowrap"不自动折行setshowmatch"显示匹配的括号setscrolloff=3"距离顶部和底部3行"setencoding=utf-8"编码setfenc=utf-8"编码setmouse=a"启用鼠标sethlsearch"搜索高亮syntaxon"语法高亮auBufNewFile,BufRead*.py\settabstop=2"tab宽度\setsofttabstop=4\setshiftwidth=4\settextwidth=79"行最大宽度\setexpandtab"tab替换为空格键\setautoindent"自动缩进\setfileformat=unix"保存文件格式setfoldmethod=indentsetfoldlevel=50map<F8>:callRunPython()<CR>func!RunPython()exec"W"if&filetype=='python'exec"!timepython2.7%"endifendfuncmap<C-n>:NERDTreeToggle<CR>autocmdFileTypepythonnoremap<buffer><F9>:callAutopep8()<CR>



python学习-vim插件安装

评论关闭