转载自:https://www.jianshu.com/p/297802d16fb4?from=timeline&isappinstalled=0
https://github.com/VundleVim/Vundle.vim
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
编辑配置文件vimrc添加如下内容
vim .vimrc
"去除VI一致性,必须
set nocompatible
"必须
filetype off
"设置Vundle的运行路径
set rtp+=/opt/vim8/share/vim/bundle/Vundle.vim
"设置插件的安装路径,vundle插件起始标志
call vundle#begin('/opt/vim8/share/vim/bundle')
"让vundle管理插件版本
Plugin 'VundleVim/Vundle.vim'
"你的所有插件需要在下面这行之前
call vundle#end()
"加载vim自带和插件相应的语法和文件类型相关脚本
filetype plugin indent on
然后运行vim8_py3,在Normal模式下运行命令PluginList
vim8_py3
回车后一个新的窗口即Vundle,会列出你安装的所有插件
运行PluginInstall会安装列表中的插件
注:删除插件只需要在vimrc配置文件中注释掉插件,在vim中用PluginClean进行清理
下面会安装不同的包,你只需将它们添加到vimrc中,然后再vim运行PluginInstall,下面将介绍一些能用到的插件
"添加nerdtree插件
Bundle 'scrooloose/nerdtree'
"设置按F2启动NerdTree
map :NERDTreeToggle
"隐藏目录树中的.pyc文件
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
可以先用PluginList查看下插件,再用PluginInstall安装
在normal模式下,按F2可以开启或者关闭树形结构,可以用鼠标点选文件打开,是不是很方便!
yum install python34-pip
pip3 install jedi
在vimrc中添加如下内容,然后再vim中执行PluginInstall安装
"添加jedi-vim代码补全插件
Plugin 'davidhalter/jedi-vim'
效果如下图:
https://github.com/Valloric/YouCompleteMe
"添加YouCompleteMe代码补全插件
Plugin 'Valloric/YouCompleteMe'
"youcompleteme 默认tab s-tab 和自动补全冲突
""let g:ycm_key_list_select_completion=['' ]
let g:ycm_key_list_select_completion = ['' ]
"let g:ycm_key_list_previous_completion=['']
let g:ycm_key_list_previous_completion = ['']
" 关闭加载.ycm_extra_conf.py提示
let g:ycm_confirm_extra_conf=0
" 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 从第2个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax=1
"force recomile with syntastic
nnoremap :YcmForceCompileAndDiagnostics
" nnoremap lo :lopen "open locationlist
"nnoremap lc :lclose "close locationlist
inoremap
" 在注释输入中也能补全
let g:ycm_complete_in_comments = 1
"在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
"注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
当YouCompleteMe在vim安装时间会有点长,需要耐心等待,安装完成后还需要进入到目录进行编译
cd .vim/bundle/YouCompleteMe/
python3 install.py --clang-completer$yum install cmake
[[email protected]]./configure --prefix=/usr/local/python3 --enable-shared --enable-optimizations
编译结束后就可以使用了,如下图,和jedi-vim还是有些不一样的:
"python语法检测
Plugin 'scrooloose/syntastic'
"添加PEP8代码风格检查
Plugin 'nvie/vim-flake8'
"配色方案
https://github.com/altercation/vim-colors-solarized
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
$ cd vim-colors-solarized/colors
$ mv solarized.vim ~/.vim/colors/
"设置主题颜色,以及设置快捷键F5
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
call togglebg#map("")
"代码折叠插件
Plugin 'tmhedberg/SimpylFold'
"开启代码折叠
set foldmethod=indent
set foldlevel=99
"设置快捷键为空格
noremap za
" 显示折叠代码的文档字符串
let g:SimpylFold_docstring_preview=1
"自动缩进
Plugin 'vim-scripts/indentpython.vim'
"在vim的normal模式下搜索文件
Plugin 'kien/ctrlp.vim'
后续还会有一些补充,附上vimrc配置文件内容
set nocompatible " required
filetype off " required
"设置Vundle的运行路径
set rtp+=/opt/vim8/share/vim/bundle/Vundle.vim
"设置插件的安装路径,vundle插件起始标志
call vundle#begin('/opt/vim8/share/vim/bundle')
"让vundle管理插件版本
Plugin 'VundleVim/Vundle.vim'
"添加nerdtree插件
Plugin 'scrooloose/nerdtree'
"使用tab键切换窗口与目录树
Plugin 'jistr/vim-nerdtree-tabs'
"添加jedi-vim代码补全插件
"Plugin 'davidhalter/jedi-vim'
Plugin 'Valloric/YouCompleteMe'
"添加PEP8代码风格检查
Plugin 'nvie/vim-flake8'
"配色方案
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
"代码折叠插件
Plugin 'tmhedberg/SimpylFold'
"自动缩进
Plugin 'vim-scripts/indentpython.vim'
"在vim的normal模式下搜索文件
Plugin 'kien/ctrlp.vim'
"Powerline状态栏
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
"你的所有插件需要在下面这行之前
call vundle#end()
"设置分割窗口
set splitbelow
set splitright
"设置窗口移动快捷键
nnoremap
nnoremap
nnoremap
nnoremap
" 设置按F2启动NerdTree
map :NERDTreeToggle
"youcompleteme 默认tab s-tab 和自动补全冲突
""let g:ycm_key_list_select_completion=['']
let g:ycm_key_list_select_completion = ['']
" let g:ycm_key_list_previous_completion=['' ]
let g:ycm_key_list_previous_completion = ['' ]
"关闭加载.ycm_extra_conf.py提示
let g:ycm_confirm_extra_conf=0
" 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 从第2个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax=1
"force recomile with syntastic
nnoremap :YcmForceCompileAndDiagnostics
"nnoremap lo :lopen " open locationlist
"nnoremap lc :lclose " close locationlist
inoremap
"在注释输入中也能补全
let g:ycm_complete_in_comments = 1
"在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
"注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"隐藏目录树种的.pyc文件
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
"设置主题颜色,以及设置快捷键F5
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
call togglebg#map("")
"开启代码折叠
set foldmethod=indent
set foldlevel=99
"设置快捷键为空格
nnoremap za
"显示折叠代码的文档字符串
let g:SimpylFold_docstring_preview=1
"python代码缩进PEP8风格
au BufNewFile,BufRead *.py,*.pyw set tabstop=4
au BufNewFile,BufRead *.py,*.pyw set softtabstop=4
au BufNewFile,BufRead *.py,*.pyw set shiftwidth=4
au BufNewFile,BufRead *.py,*.pyw set textwidth=79
au BufNewFile,BufRead *.py,*.pyw set expandtab
au BufNewFile,BufRead *.py,*.pyw set autoindent
au BufNewFile,BufRead *.py,*.pyw set fileformat=unix
"对其他文件类型设置au命令
au BufNewFile,BufRead *.js, *.html, *.css set tabstop=2
au BufNewFile,BufRead *.js, *.html, *.css set softtabstop=2
au BufNewFile,BufRead *.js, *.html, *.css set shiftwidth=2
"高亮显示行伟不必要的空白字符
highlight Whitespace ctermbg=red guibg=red
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match Whitespace /\s\+$\ \+/
"设置行号显示
set nu
"设置utf-8编码
set encoding=utf-8
let python_highlight_all=1
syntax on
filetype plugin indent on