vim 8.0插件配置

安装插件需要有一个插件管理器。此处使用的是Vundle

下载地址:https://github.com/VundleVim/Vundle.vim.git

1、vim安装到/usr/local/vim目录下,vimrc在/usr/local/vim/share/vim/中

vimrc可以使用此处的,或者在用户目录下新建一个.vimrc使用,此处就直接使用默认的vimrc

创建插件目录:

mkdir -p /usr/local/vim/share/vim/bundle

2、配置YouCompleteMe

# cd /usr/local/vim/share/vim/bundle/YouCompleteMe

# python install.py –clang-completer –go-completer

3、此处用到powerline,下面是安装步骤:

1、用pip安装
pip3 install powerline-status

2、查看并记录location位置
pip3 show powerline-status
......
Location: /usr/local/python/lib/python3.5/site-packages
......

3、配置powerline到bash(此处可选,如果喜欢可以配置)
在~/.bashrc中添加
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/local/python/lib/python3.5/site-packages/powerline/bindings/bash/powerline.sh
重载bashrc
source ~/.bashrc
在bashrc中加这些以后重新启动终端如果报错可以加几个映射:
ln -s /usr/local/python/bin/powerline /usr/local/bin
ln -s /usr/local/python/bin/powerline-config /usr/local/bin
ln -s /usr/local/python/bin/powerline-daemon /usr/local/bin

3、此处主要是在vim中使用powerline样式,需要在vimrc中添加如下设置
set rtp+=/usr/local/python/lib/python3.5/site-packages/powerline/bindings/vim
set laststatus=2
set t_Co=256

4、记录几个常用插件配置

" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	2017 Sep 20
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Get the defaults that most users want.
source $VIMRUNTIME/defaults.vim

if has("vms")
  set nobackup		" do not keep a backup file, use versions instead
else
  set backup		" keep a backup file (restore to previous version)
  if has('persistent_undo')
    set undofile	" keep an undo file (undo changes after closing)
  endif
endif

if &t_Co > 2 || has("gui_running")
  " Switch on highlighting the last used search pattern.
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Add optional packages.
"
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
" The ! means the package won't be loaded right away but when plugins are
" loaded during initialization.
if has('syntax') && has('eval')
  packadd! matchit
endif

"去除VI一致性,必须
set nocompatible
"必须             
filetype off                  

"设置Vundle的运行路径
set rtp+=/usr/local/vim/share/vim/bundle/Vundle.vim
"设置插件的安装路径,vundle插件起始标志
call vundle#begin('/usr/local/vim/share/vim/bundle')

"让vundle管理插件版本
Plugin 'VundleVim/Vundle.vim'
"添加nerdtree插件
Plugin 'scrooloose/nerdtree'
"添加YouCompleteMe代码补全插件
Plugin 'Valloric/YouCompleteMe'
"添加PEP8代码风格检查
Plugin 'nvie/vim-flake8'
" Ctrlp模糊搜索使用
Plugin 'ctrlpvim/ctrlp.vim'
"代码折叠插件
Plugin 'tmhedberg/SimpylFold'
"自动缩进
Plugin 'vim-scripts/indentpython.vim'
" 底部状态栏
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'

"你的所有插件需要在下面这行之前
call vundle#end()
"加载vim自带和插件相应的语法和文件类型相关脚本
filetype plugin indent on

"设置按F2启动NerdTree
map <F2> :NERDTreeToggle<CR>
"隐藏目录树中的.pyc文件
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree

" ####YouComPleteMe插件配置
"youcompleteme  默认tab  s-tab 和自动补全冲突
"let g:ycm_key_list_select_completion=['<c-n>']
let g:ycm_key_list_select_completion = ['<Down>']
"let g:ycm_key_list_previous_completion=['<c-p>']
let g:ycm_key_list_previous_completion = ['<Up>']
"关闭加载.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 <F5> :YcmForceCompileAndDiagnostics<CR>
"nnoremap <leader>lo :lopen<CR> "open locationlist
"nnoremap <leader>lc :lclose<CR>    "close locationlist
inoremap <leader><leader> <C-x><C-o>
"在注释输入中也能补全
let g:ycm_complete_in_comments = 1
"在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
"注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0

" Ctrlp模糊搜索使用
nnoremap <leader>p  :CtrlP<CR>
nnoremap <leader>b  :CtrlPBuffer<CR>
let g:ctrlp_match_window = 'bottom,order:ttb'
let g:ctrlp_switch_buffer = 0
let g:ctrlp_working_path_mode = ''

"开启代码折叠
set foldmethod=indent
set foldlevel=99
"设置快捷键为空格
noremap <space> 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 splitbelow
set splitright
"快捷键,ctrl+l切换到左边布局,ctrl+h切换到右边布局
"ctrl+k切换到上面布局,ctrl+j切换到下面布局
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" *********************************************
" vim-airline
" *********************************************
" 开启powerline字体
let g:airline_powerline_fonts = 1
" 使用powerline包装过的字体
set guifont=Source\ Code\ Pro\ for\ Powerline:h14

"设置行号显示
set number	
set tabstop=8 expandtab shiftwidth=4 softtabstop=4
" 共享剪切板
set clipboard=unnamed

"设置utf-8编码
set encoding=utf-8

" 配置powerline到vim中
set rtp+=/usr/local/python/lib/python3.5/site-packages/powerline/bindings/vim
set laststatus=2
set t_Co=256

let python_highlight_all=1
syntax on

"加载vim自带和插件相应的语法和文件类型相关脚本
filetype plugin indent on

map <F5> :call RunPython()<CR>
func! RunPython()
    exec "W"
    if &filetype == 'python'
        exec "!time python %"
    endif
endfunc

"autocmd bufnewfile *.py call HeaderPython() 
"function HeaderPython() 
"    call setline(1, "#!/usr/bin/python") 
"    call append(1, "# -*- coding:UTF-8 -*-") 
"endfunc
" Python 创建py文档默认注释
function InsertPythonComment()
    exe 'normal'.1.'G'
    let line = getline('.')
    if line =~ '^#!.*$' || line =~ '^#.*coding:.*$'    
        return
    endif
    normal O
    call setline('.', '#!/usr/bin/python')
    normal o
    call setline('.', '# -*- coding:utf-8 -*-')
    normal o
    call setline('.', '#')
    normal o
    call setline('.', '# Author : '.g:python_author)
    normal o
    call setline('.', '# E-mail : '.g:python_email)
    normal o
    call setline('.', '# Date   : '.strftime("%y/%m/%d %H:%M:%S"))
    normal o
    call setline('.', '# Desc   : ')
    normal o
    call setline('.', '#')
    normal o
    call cursor(7, 12)
endfunction
function InsertCommentWhenOpen()
    if a:lastline == 1 && !getline('.')
        call InsertPythonComment()
    endif
endfunction
au FileType python :%call InsertCommentWhenOpen()
au FileType python map <F4> :call InsertPythonComment()<cr>
let g:python_author = 'name'               
let g:python_email  = '@@@@'