Ubuntu12.04安装YouCompleteMe等相关插件 (已附上我现在用的完整.vimrc配置文件)

序言

    使用Ubuntu和vim已经有一段时间了,对于Vim下的各种插件,总是感觉很乱的样子  ,在网上闲逛着,发现了一个个人博客提到了Vim代码补全这回事,并提到了YouCompleteMe这个插件。于是决定将YouCompleteMe这个插件安装好试用一下,同时,用Vundle也好让我将.vim文件夹下的文件清理一下.

准备

1.相关链接

  1. PPA for vim 7.4. YouCompleteMe插件要求Vim 版本在7.3.584及以上,而Ubuntu13.04源中的Vim已经比较老了。所以,我们可以在源中添加PPA,或者编译源码手动更新VIM的版本。
  2. Vundle. 这是一个新生代vim插件管理器,使用git进行插件安装和更新。以前有一个pathogen。插件管理器的好处是:使用简单,自动化管理vim的插件。让你的.vim文件夹远离混乱不堪的窘境,从此一手.vimrc走天下。
  3. Clang+LLVM. LLVM+Clang是Apple公司资助的一个项目,YouCompleteMe精确的补全功能完全依赖于Clang的代码解析。我们需要安装好Clang 3.2+以便为YCM提供支持。
  4. SVN和Git。用于从代码库中检出源代码。在Ubuntu下这两个软件的安装都非常简单,使用apt-get命令即可安装完成。
  5. YouCompleteMe和Syntastic.这两个插件都是配合使用的。YCM不用再说,Syntastic用于源码的实时检查。具体效果如同Eclipse一样,在代码编写的过程中即可实时报告语法错误。
  6. Cmake.后面在编译过程中会使用到,安装命令:sudo apt-get install cmake.

2.升级VIM

升级到7.3.584+。Ubuntu下需要手动添加PPA(Personal Package Archives),可以使用命令行add-apt-repository来进行添加,如:

$ sudo add-apt-repository ppa:nmi/vim-snapshots
$ sudo apt-get update
$ sudo apt-get install vim

某些PPA也提供了源地址,那么就可以直接打开/etc/apt/source.list进行添加。二者的本质是一样的。如从源码编译vim,可参考这里。

下载Vundle。Vundle托管在Github上,需要使用到git来检出源代码。

$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

以上命令直接将源代码检出到了~/.vim/bundle/vundle这个目录下。

下载完了vundle后,需要配置好.vimrc文件。需要配置的模板如下(摘在github):


set nocompatible              " be iMproved
filetype off                  " required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required! 
Bundle 'gmarik/vundle'

" My bundles here:
"
" original repos on GitHub
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'tpope/vim-rails.git'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
" non-GitHub repos
Bundle 'git://git.wincent.com/command-t.git'
" Git repos on your local machine (i.e. when working on your own plugin)
Bundle 'file:///Users/gmarik/path/to/plugin'
" ...

filetype plugin indent on     " required!
  1. 其中需要说明的是:filetype off这一条实际上并不需要。因为这条命令将导致语法着色失败。我的.vimrc里面并没配置这一条。当所需要的vim插件托管在Github上时,该插件的可写成“Bundle 'scrooloose/syntastic'”;当插件在www.vim.org上面时,我们只需要写明该插件的名称,还要加上.vim扩展名。否则vundle无法更新该插件。基本上这两种情况可以满足我们大部分人的需要了。

  2. vundle的使用。先将~/.vim/下面原先安装的插件都"rm -rf"掉吧,由vundle来接手管理工作。打开一个vim窗口,执行命令:BundleInstall。接下来vundle会自动去网上将相关插件下载下来并安装好。在此过程中,vundle还会:helptags命令。因此,我们可以直接在vim中查看插件的帮助文档。要删除一个插件也很简单,先在~/.vimrc中移除该插件条目,然后进入vim执行命令:BundleClean。嘿嘿,vundle将自动清除掉插件的文件夹!狂拽炫酷吊炸天!

  3. 安装llvm & clang
    到 http://llvm.org/releases/download.html#3.3 下载编译后的二进制文件
    http://llvm.org/releases/3.3/clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz
    tar -zxf clang3.3-amd64-Ubuntu-12.04.2.tar.gz
    cd clang+llvm-3.3-amd64-Ubuntu-12.04.2/
    cp -r * /

    如果在命令行输入clang,输出clang: error: no input files,说明安装成功
3 下载 Vundle
 

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

Vundle可以让Vim自动从github等地方下载插件,而不用每次去vim.org上手动下载


修改.vimrc

set nocompatible              " be iMproved
set nu
set noswapfile
syntax on
set backspace=2
set tabstop=2
set shiftwidth=2
set completeopt=menu
:colorscheme ron
set cindent
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/syntastic'
""""""""""syntastic""""""""""""
let g:syntastic_check_on_open = 1
let g:syntastic_cpp_include_dirs = ['/usr/include/']
let g:syntastic_cpp_remove_include_errors = 1
let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_compiler = 'clang++'
"set error or warning signs
let g:syntastic_error_symbol = 'x'
let g:syntastic_warning_symbol = '!'
"whether to show balloons
let g:syntastic_enable_balloons = 1

""""""""""""YCM""""""""""""""""""""
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0


然后打开vim
在命令模式下输入
:BundleInstall,就会发现vim自动开始下载插件了
NOTE:
YouCompleteMe插件要下载很久,请稍安勿躁:-)

4. 编译ycm_core & ycm_support_libs


cd ~
mkdir ~/ycm_build
cd ~/ycm_build
cmake -G "Unix Makefiles"  ~/.vim/bundle/YouCompleteMe/cpp -DEXTERNAL_LIBCLANG_PATH=/lib/libclang.so
make ycm_core
make ycm_support_libs

这里要注意的是-DEXTERNAL_LIBCLANG_PATH这个参数,用于指定libclang.so的位置

5. 配置.ycm_extra_conf.py
~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py
在这个文件的flags尾部添加:
'-isystem',
'/usr/include',
'-isystem',
'/usr/include/c++/'


以下是我找到几个.vimrc文件整理出来的 功能比较齐全

""""" """ " Love your Life, please " """ """""
        """"""""" """ " """ """""""""
		
" Source a global configuration file if available
"if filereadable("/etc/vim/vimrc.local")
"	source /etc/vim/vimrc.local
"endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                  Vundle                   """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
" git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
" BundleInstall

set nocompatible	" be iMproved
filetype off		" required!

set rtp+=~/.vim/bundle/vundle/ 
call vundle#rc()

" let Vundle manage Vundle
" required
Bundle 'gmarik/vundle'

" My Bundle here:
"""""""""""""""""""""""""""""""
" 语法高亮
"""""""""""""""""""""""""""""""
Bundle 'molokai'
Bundle 'JavaScript-syntax'
Bundle 'jQuery'
Bundle 'othree/html5.vim'
Bundle 'groenewege/vim-less'
Bundle 'hail2u/vim-css3-syntax'
Bundle 'Markdown'
Bundle 'Markdown-syntax'
"Bundle 'php.vim-html-enhanced' "一个TAB为3个空格 = =
"增加了rgb显示颜色和同行显示多处颜色
Bundle 'Valloric/vim-operator-highlight'

" User Interface
"""""""""""""""""""""""""""""""
"Bundle 'winmanager'
Bundle 'scrooloose/nerdtree'
Bundle 'scrooloose/nerdcommenter'
Bundle 'xolox/vim-easytags'
Bundle 'xolox/vim-misc'
"Bundle 'taglist.vim'
Bundle 'majutsushi/tagbar'
Bundle 'fholgado/minibufexpl.vim'
"Bundle 'bufexplorer.zip'
Bundle 'Lokaltog/vim-powerline'
"Make gvim-only colorschemes work transparently in terminal vim
Bundle 'CSApprox' 

" AutoComplete
"""""""""""""""""""""""""""""""
"Bundle 'AutoComplPop'
"Bundle 'msanders/snipmate.vim' "自带了snippets
"Bundle 'Pydiction'

Bundle 'Rip-Rip/clang_complete'
Bundle 'Shougo/neocomplcache'
Bundle 'Shougo/neosnippet'
Bundle 'Shougo/neosnippet-snippets'
Bundle 'honza/vim-snippets'
Bundle 'davidhalter/jedi-vim'
"Bundle 'Valloric/YouCompleteMe'

" support for snipmate 
"Bundle 'MarcWeber/vim-addon-mw-utils'
"Bundle 'tomtom/tlib_vim'
"Bundle 'honza/snipmate-snippets'
"Bundle 'spf13/snipmate-snippets'
"Bundle 'garbas/vim-snipmate'

Bundle 'ZenCoding.vim'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'tpope/vim-surround'
"Bundle 'Raimondi/delimitMate'
Bundle 'Townk/vim-autoclose'
Bundle 'matchit.zip'
" press K on a function for full PHP manual
"Bundle 'spf13/PIV'
Bundle 'shawncplus/phpcomplete.vim'

" Tools
""""""""""""""""""""""""""""""
Bundle 'udonmai/Conque-Shell'
Bundle 'grep.vim'

Bundle 'scrooloose/syntastic'
Bundle 'YankRing.vim'
Bundle 'sjl/gundo.vim'
Bundle 'wincent/Command-T'
Bundle 'derekwyatt/vim-fswitch'
"Bundle 'vim-flake8'

filetype plugin indent on     " required!
"
" Brief help
" :BundleList          - list configured bundles
" :BundleInstall(!)    - install(update) bundles
" :BundleSearch(!) foo - search(or refresh cache first) for foo
" :BundleClean(!)      - confirm(or auto-approve) removal of unused bundles
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Bundle command are not allowed..


""""""""""""""""""""""""""""""Ace""""""""""""""""""""""""""""""""""""
" 一般设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"runtime! debian.vim

"颜色
colorscheme molokai

"字体
set guifontwide=Monaco:h13
set guifont=Monaco:h13
"set guifontwide=YaHei\ Consolas\ Hybrid\ 12 
"set guifont=YaHei\ Consolas\ Hybrid\ 12 

" 设定默认解码
set enc=utf-8
set fenc=utf-8
set fencs=utf-8,gbk,gb2312,gb18030,cp936,usc-bom,euc-jp

" 不要使用vi的键盘模式,而是vim自己的
set nocompatible

" history文件中需要记录的行数
set history=600

" 在处理未保存或只读文件的时候,弹出确认
set confirm

" 与windows共享剪贴板
set clipboard+=unnamed

" 侦测文件类型
filetype on

" 载入文件类型插件
filetype plugin on

" 为特定文件类型载入相关缩进文件
filetype indent on

" 保存全局变量
set viminfo+=!

" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-

" 语法高亮
syntax on

" 显示行号(下面有自动侦测文件类型显示)
"set nu

" 高亮字符,让其不受100列限制
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%101v.*'

" 状态行颜色
highlight StatusLine guifg=SlateBlue guibg=Yellow
"highlight StatusLineNC guifg=Gray guibg=White

" 默认窗口分割方向
"set splitbelow
set splitright

" 显示匹配
set showmatch

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 不要备份文件(根据自己需要取舍)
set nobackup

" 不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide

" 字符间插入的像素行数目
set linespace=0

" 增强模式中的命令行自动完成操作
set wildmenu

" 在状态行上显示光标所在位置的行号和列号
set ruler
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)

" 命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2

" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2

" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l

" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key

" 启动的时候不显示那个援助索马里儿童的提示
"set shortmess=atI

" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0

" 不让vim发出讨厌的滴滴声
set noerrorbells

" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮显示匹配的括号
set showmatch

" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1

" 在搜索的时候忽略大小写
set ignorecase

" 不要高亮被搜索的句子(phrases)
" set nohlsearch

" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch

" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3

" 不要闪烁
set novisualbell

" 我的状态行显示的内容(包括文件类型和解码)
set statusline=%F%m%r%h%w\[POS=%l,%v][%p%%]\%{strftime(\"%d/%m/%y\ -\ %H:%M\")}

" 总是显示状态行
set laststatus=2

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自动格式化
set formatoptions=tcrqn

" 继承前一行的缩进方式,特别适用于多行注释
set autoindent

" 为C程序提供自动缩进
set smartindent

" 使用C样式的缩进
set cindent

" 制表符为4
set tabstop=4

" 统一缩进为4
set softtabstop=4
set shiftwidth=4

" 不要用空格代替制表符
set noexpandtab

" 不要换行
set nowrap

" 在行和段开始处使用制表符
set smarttab

" 显示Tab和结尾
set list
set listchars=tab:>.,trail:.,extends:#,nbsp:.
"set listchars=tab:▸\ ,eol:¬
"set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$

" vim自身设置,不显示预览窗口
set completeopt=menuone 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示
if has("autocmd") 
	autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4
	autocmd FileType xml,html,css,js,javascript,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby,markdown,sh,md set number
	autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
	autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o
	autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
	"autocmd FileType html,htmldjango,jinjahtml,eruby,mako let b:closetag_html_style=1
	"autocmd FileType html,xhtml,xml,htmldjango,jinjahtml,eruby,mako source ~/.vim/bundle/closetag.vim/plugin/closetag.vim

	" JavaScript 语法高亮
	au FileType html,javascript let g:javascript_enable_domhtmlcss = 1
	au BufRead,BufNewFile *.js setf jquery
	
	autocmd BufReadPost *
	\ if line("'\"") > 0 && line("'\"") <= line("$") |
		\ exe " normal g`\"" |
	\ endif
endif "has("autocmd")"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 键映射
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
inoremap jj <ESC>
noremap <Leader>q :qa<cr>

" 分屏间移动
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-H> <C-W>h
map <C-L> <C-W>l

" F5编译和运行C程序,F6编译和运行C++程序
" 请注意,下述代码在windows下使用会报错
" 需要去掉./这两个字符

" C的编译和运行
"""""""""""""""""""""""""""""""
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"
endfunc

" C++的编译和运行
"""""""""""""""""""""""""""""""
map <F6> :call CompileRunGpp()<CR>
func! CompileRunGpp()
exec "w"
exec "!g++ % -o %<"
exec "! ./%<"
endfunc

"map <F8> :w<CR>:call CompileRun()<CR> 
"map <F8><F8> :w<CR>:call Debug()<CR>

func CompileRun() 
    exec “w”  
    if &filetype == ‘c’  
        exec “!gcc % -g -o %<” 
        exec “!.\/%<” 
    elseif &filetype ==’cpp’ 
        exec “!g++ % -g -o %<” 
        exec “!.\/%<” 
    elseif &filetype == ‘python’ 
        exec “!python %” 
    endif 
endfunc

func Debug() 
    exec “w”  
    if &filetype == ‘c’  
        exec “!rm %<” 
        exec “!gcc % -g -o %<” 
        exec “!gdb %<” 
    elseif &filetype == ‘cpp’ 
        exec “!rm %<” 
        exec “!g++ % -g -o %<” 
        exec “!gdb %<” 
        exec “!rm %<.class” 
    elseif &filetype == ‘python’ 
        exec “!pdb %” 
    endif 
endfunc

" 能够漂亮地显示.NFO文件
"""""""""""""""""""""""""""""""
"set encoding=utf-8
function! SetFileEncodings(encodings)
	let b:myfileencodingsbak=&fileencodings
	let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
	let &fileencodings=b:myfileencodingsbak
	unlet b:myfileencodingsbak
endfunction

au BufReadPre *.nfo call SetFileEncodings('cp437')|set ambiwidth=single 
au BufReadPost *.nfo call RestoreFileEncodings()

" 高亮显示普通txt文件(需要txt.vim脚本)
au BufRead,BufNewFile *  setfiletype txt

" 用空格键来开关折叠
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

" minibufexpl插件的一般设置
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

" 设置配色和CSApprox
set t_Co=256
let g:CSApprox_attr_map={'bold':'bold','italic':'','sp':''}
"colo elise

" 纵向线
augroup cch
	autocmd! cch
	autocmd WinLeave * set nocursorline
	autocmd WinLeave * set nocursorcolumn
	autocmd WinEnter,BufRead * set cursorline
	autocmd WinEnter,BufRead * set cursorcolumn
augroup END

" 启用WinManager
"let g:winManagerWindowLayout='FileExplorer'
"nmap wm :WMToggle<cr>
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                  PHP Sp                   """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
" php editing
" remove CR at end of lines
let PHP_removeCRwhenUnix = 1
" Set up automatic formatting
set formatoptions+=tcqlro
" Set maximum text width (for wrapping)
set textwidth=110
"配置vimrc, 使得keywordprg=”help” 注:一般情况下,keywordprg默认是!man或!man -s
autocmd BufNewFile,Bufread *.module,*.inc,*.php set keywordprg="help"
"autoload _vimrc
"autocmd! bufwritepost _vimrc source %

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"               Python sp                   """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
"pydiction 1.2 python auto complete
"filetype plugin on
"let g:pydiction_location = '~/.vim/bundle/Pydiction'
"defalut g:pydiction_menu_height == 15	
"let g:pydiction_menu_height = 20 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                 TagBar                    """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <F10> :TagbarToggle<CR>   "设置快捷键
let g:tarbar_ctags_bin = '/usr/local/bin/ctags'
let g:tagbar_width = 40       "设置宽度,默认为40
"autocmd VimEnter * nested :call tagbar#autoopen(1)    "打开vim时自动打开tagbar
"let g:tagbar_left = 1         "在左侧
let g:tagbar_right = 1 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                  Cscope                   """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
"设定是否使用 quickfix 窗口来显示 cscope 结果
set cscopequickfix=s-,c-,d-,i-,t-,e- 

"快捷键
nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"             MiniBufExplorer               """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
"<C-Tab>	向前循环切换到每个buffer上,并在但前窗口打开
"<C-S-Tab>	向后循环切换到每个buffer上,并在但前窗口打开
let g:miniBufExplMapCTabSwitchBufs = 1

"用<C-箭头键>切换到上下左右窗口中去
let g:miniBufExplMapWindowNavArrows = 1

"则可以用<C-h,j,k,l>切换到上下左右的窗口中去,就像:
"C-w,h j k l    向"左,下,上,右"切换窗口.
"let g:miniBufExplMapWindowNavVim = 1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                 NerdTree                  """""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""" 
"设置F9为开启快捷方式
map <F9> :NERDTreeToggle<CR>
"关闭文件后只剩NerdTree的时候也一并关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"               NerdCommenter               """""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""" 
let mapleader="," "修改<leader>的映射键为','

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                  Grep                     """""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""" 
nnoremap <silent> <F3> :Grep<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"               Powerline                   """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:Powerline_symbols = 'fancy'  " 启用 smartcase.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"             NeoComplCache                 """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
" 停用 AutoComplPop.
"let g:acp_enableAtStartup = 0
" 启用 neocomplcache.
let g:neocomplcache_enable_at_startup = 1

let g:neocomplcache_enable_smart_case = 1
" 启用大写字母补全.
let g:neocomplcache_enable_camel_case_completion = 1
" 启用下划线补全.
let g:neocomplcache_enable_underbar_completion = 1
" 设定最小语法关键词长度.
let g:neocomplcache_min_syntax_length = 2

let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
" 定义字典.
let g:neocomplcache_dictionary_filetype_lists = {
	\ 'default' : '',
	\ 'vimshell' : $HOME.'/.vimshell_hist',
	\ 'scheme' : $HOME.'/.gosh_completions',
	\ 'php' : $HOME.'/.vim/dict/php.dic',
	\ }
"	\ 'css' : $HOME.'.vim/dict/css.dic',
"	\ 'javascript' : $HOME.'.vim/dict/javascript.dic'

"include_complete be abled
let g:neocomplcache_ctags_program = '/usr/local/bin/ctags'

" 定义关键词.
if !exists('g:neocomplcache_keyword_patterns')
let g:neocomplcache_keyword_patterns = {}
endif
let g:neocomplcache_keyword_patterns['default'] = '\h\w*'

" 插件键映射.
imap <C-k>     <Plug>(neocomplcache_snippets_expand)
smap <C-k>     <Plug>(neocomplcache_snippets_expand)
inoremap <expr><C-g>     neocomplcache#undo_completion()
inoremap <expr><C-l>     neocomplcache#complete_common_string()

" 类似于SuperTab用法 .
"imap <expr><TAB> neocomplcache#sources#snippets_complete#expandable() ? "\<Plug>(neocomplcache_snippets_expand)" : pumvisible() ? "\<C-n>" : "\<TAB>"

" 推荐的键映射.
" <CR>: close popup and save indent.
inoremap <expr><CR>  neocomplcache#smart_close_popup() . "\<CR>"
" <TAB>: completion. NO USE with snipmate
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><C-Y>  neocomplcache#close_popup()
inoremap <expr><C-e>  neocomplcache#cancel_popup()

"inoremap <expr><Enter>  pumvisible() ? neocomplcache#close_popup()."\<C-n>" : "\<Enter>"
"inoremap <expr><Enter>  pumvisible() ? "\<C-Y>" : "\<Enter>"

" 类似于AutoComplPop用法 .
"let g:neocomplcache_enable_auto_select = 1
" 类似于 Shell 用法(不推荐).
"set completeopt+=longest
"let g:neocomplcache_enable_auto_select = 1
"let g:neocomplcache_disable_auto_complete = 1
"inoremap <expr><TAB>  pumvisible() ? "\<Down>" : "\<TAB>"
"inoremap <expr><CR>  neocomplcache#smart_close_popup() . "\<CR>"

" 启用 omni 补全.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
"autocmd FileType php setlocal omnifunc=phpcomplete#CompletePHP "vim默认
"autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete

" 启用 heavy omni 补全.
if !exists('g:neocomplcache_omni_patterns')
	let g:neocomplcache_omni_patterns = {}
endif
if !exists('g:neocomplcache_omni_functions')
	let g:neocomplcache_omni_functions = {}
endif
if !exists('g:neocomplcache_force_omni_patterns')
	let g:neocomplcache_force_omni_patterns = {}
endif

"let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
"let g:neocomplcache_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'

" 兼容clang_complete
let g:neocomplcache_force_overwrite_completefunc = 1
let g:neocomplcache_force_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
let g:neocomplcache_force_omni_patterns.objc = '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.objcpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'

" 兼容jedi
let g:neocomplcache_force_omni_patterns.python = '[^. \t]\.\w*'
let g:neocomplcache_omni_functions.python = 'jedi#complete'

" rank sourch list
let g:neocomplcache_source_rank = {
	\ 'buffer_complete'     : 6,
	\ 'dictionary_complete' : 5,
	\ 'syntax_complete'     : 4,
	\ }

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                NeoSnippet                """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
"Plugin key-mappings.
imap <C-k>	<Plug>(neosnippet_expand_or_jump)
smap <C-k>	<Plug>(neosnippet_expand_or_jump)
xmap <C-k>	<Plug>(neosnippet_expand_target)

"SuperTab like snippets behavior.
"imap <expr><TAB> neosnippet#expandable() ? "\<Plug>(neosnippet_expand_or_jump)" : pumvisible() ? "\<C-n>" : "\<TAB>"
"smap <expr><TAB> neosnippet#expandable() ? "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
imap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)"
\: pumvisible() ? "\<C-n>" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)"
\: "\<TAB>"

"For snippet_complete marker.
if has('conceal')
	set conceallevel=2 concealcursor=i
endif

" Tell Neosnippet about the other snippets
" let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"              Clang_Complete              """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:clang_complete_copen = 1
let g:clang_periodic_quickfix = 1
let g:clang_snippets = 1
let g:clang_close_preview = 1
let g:clang_use_library = 1
let g:clang_complete_auto = 0
let g:clang_auto_select = 0
"let g:clang_user_options = '|| exit 0'

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"               Syntastic                  """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:syntastic_check_on_open = 1
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚠'
let g:syntastic_auto_loc_list = 1
let g:syntastic_loc_list_height = 5
let g:syntastic_python_checkers=['flake8']
let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd']
"phpcs,tab 4个空格,编码参考使用CodeIgniter风格
let g:syntastic_phpcs_conf = "--tab-width=4 --standard=CodeIgniter"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                  Gundo                   """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
" f8 toggles the Gundo plugin window
nnoremap <F8> :GundoToggle<CR>
let g:gundo_width = 25
let g:gundo_close_on_revert = 1
let g:gundo_preview_bottom = 1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                ZenCoding                 """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:user_zen_expandabbr_key='<C-u>'

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                EasyMotion                """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
"兼容大部分配色方案
hi link EasyMotionTarget ErrorMsg
hi link EasyMotionShade  Comment

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                AutoClose                 """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:AutoClosePairs_add = "<>"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                YankRing                  """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:yankring_history_dir = '~/.vim/yankring'
" this is so that single char deletes don't end up in the yankring
let g:yankring_min_element_length = 2
let g:yankring_window_height = 14
nnoremap <leader>r :YRShow<CR>
"
"this makes Y yank from the cursor to the end of the line, which makes more
"sense than the default of yanking the whole current line (we can use yy for
"that)
function! YRRunAfterMaps()
    nnoremap Y   :<C-U>YRYankCount 'y$'<CR>
endfunction

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"               Command-T                  """""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:CommandTMaxHeight          = 30
let g:CommandTMatchWindowReverse = 0 " shows results in reverse order

" MacVim doesn't use tab focus to switch from command-t input field to the file
" list, so using j and k for next and prev screws everything up. But it does
" work on linux so let's use it there.
if has("gui_gtk2")
	let g:commandtselectnextmap  = [ '<down>' ]
	let g:commandtselectprevmap  = [ '<up>' ]
endif

set wildignore+=*.o,*.obj,.git,*.pyc,*.so,blaze*,READONLY,llvm,Library*,CMakeFiles
nnoremap <leader>t :CommandT<cr>
nnoremap <leader>n :CommandTBuffer<cr>
nnoremap <leader>' :CommandTFlush<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"                 jedi                     """"""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:jedi#popup_on_dot = 0

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"               EasyTags                   """"""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
" 给每个目录单独建tag文件
set tags=./.tags;,~/.vim/tags
autocmd FileType php :set tags+=~/.vim/tags/php
let g:easytags_cmd = '/usr/local/bin/ctags'
let g:easytags_file = '~/.vim/tags/tags'
"let g:easytags_dynamic_files = 1

nnoremap <leader>ut :UpdateTags!<CR>
nnoremap <leader>ht :HighlightTags<CR>
nnoremap <silent><leader>hh :let b:easytags_auto_highlight = 1<CR>
nnoremap <silent><leader>nh :let b:easytags_auto_highlight = 0<CR>

let g:easytags_resolve_links = 1
" 分语言并汇总
"let g:easytags_by_filetype = '~/.vim/tags'
" 递归遍历目录 - vim会停滞不动
"let g:easytags_autorecurse = 1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"               FSwitch                    """"""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""
" A "companion" file is a .cpp file to an .h file and vice versa

" Opens the companion file in the current window
nnoremap <Leader>sh :FSHere<cr>
" Opens the companion file in the window to the left (window needs to exist)
" This is actually a duplicate of the :FSLeft command which for some reason
" doesn't work.
nnoremap <Leader>sl :call FSwitch('%', 'wincmd l')<cr>
" Same as above, only opens it in window to the right
nnoremap <Leader>sr :call FSwitch('%', 'wincmd r')<cr>
" Creates a new window on the left and opens the companion file in it
nnoremap <Leader>sv :FSSplitLeft<cr>





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值