以前一直是用别人配置好的VIM,搞得我要去习惯别人的操作习惯,感觉心里很不舒服,而且以前用VIM一直不多,所以也就一直将就着,但是现在我决定自己配置一下自己的VIM,当然不免要参考下别人的配置方案,符合自己的就直接借鉴过来,不符合自己的就去掉,网上很多人都用Python,而我就还没有学习,所以那些人的配置方案对我来说就是一种多余。
下面说一下我的配置思路:TagBar(显示程序的类和函数等信息,方便跳转),neocomplcache(主要是代码补全),nerdcommenter(主要是可以添加注释),vim-airline(添加更加漂亮的状态行),vim-bufferline(提供缓冲区的支持),vundle(用来管理我的插件),OmniCppComplete(主要是弥补Neocomplcache的不足,后者在结构体成员方面功能不是很好),UndoTree(可以看到以往的修改,方便回到过去的状态), 还有就是一些插件依赖的插件了,另外这些插件基本都是老外写的,所以我觉得我们应该去他们的GitHub上去查找详细的帮助,此外随插件提供了很丰富的帮助文档。
下面贴上我自己的配置文件信息:
set shiftwidth=4
set tabstop=4
set softtabstop=4
" Indentation
set smartindent
set cindent
syntax enable
"colorscheme solarized
set nocompatible
set showcmd
set number
filetype on
set autoread
autocmd Filetype c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
set completeopt=preview,menu
set clipboard+=unnamed
set ruler
set cursorline
set guioptions-=T
set guioptions-=m
set noeb
set confirm
set noexpandtab
set hlsearch
set incsearch
"
" Vundle
" https://github.com/gmarik/vundle
"
"
filetype plugin indent on
set rtp+=~/.vim/bundle/vundle/
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'bling/vim-airline'
Plugin 'bling/vim-bufferline'
Plugin 'mbbill/undotree'
Plugin 'majutsushi/tagbar'
Plugin 'kien/ctrlp.vim'
Plugin 'shougo/neocomplcache'
Plugin 'shougo/vimproc.vim'
Plugin 'shougo/neosnippet'
Plugin 'shougo/neocomplete'
Plugin 'shougo/neosnippet-snippets'
Plugin 'STL-improved'
Plugin 'scrooloose/nerdcommenter'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'scrooloose/nerdtree'
Plugin 'ltercation/vim-colors-solarized'
Plugin 'OmniCppComplete'
call vundle#end()
filetype plugin indent on
set laststatus=2
set t_Co=256
"TagBar
nnoremap <silent> <F9> :TagbarOpen<CR>
"bufferline
let g:bufferline_echo = 0
autocmd VimEnter *
\ let &statusline='%{bufferline#refresh_status()}'
\ .bufferline#get_status_string()
"NerdTree
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>
"Neocomplcache
" Disable AutoCompPop
let g:acp_enableAtStartup = 0
" Use neocomplcache
let g:neocomplcache_enable_at_startup=1
" Use smartcase
let g:neocomplcache_enable_smart_case=1
" Set minimum syntax keyword length
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
" Enable heavy features
" Use camel case completion.
" let g:neocomplcache_enable_camel_case_completion = 1
" Use underbar completion
" let g:neocomplcache_enable_underbar_completion = 1
"
" Define dictionary.
let g:neocomplcache_dictionary_filetype_lists = {
\ 'default' : '',
\ 'vimshell' : $HOME.'/.vimshell_hist',
\ 'scheme' : $HOME.'/.gosh_completions'
\}
" Define keyword.
if !exists('g:neocomplcache_keyword_patterns')
let g:neocomplcache_keyword_patterns = {}
endif
let g:neocomplcache_keyword_patterns['default'] = '\h\w'
"Plugin key-mappings
inoremap <expr><C-g> neocomplcache#undo_completion()
inoremap <expr><C-l> neocomplcache#complete_common_string()
"Recommended key-mappings
"<CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return neocomplcache#smart_close_popup() . "\<CR>"
" For no inserting <CR> key. " return pumvisible() ? neocomplcache#close_popup() : "\<CR>" endfunction
endfunction
" <TAB> completion
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()
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? neocomplcache#close_popup() :
"\<Space>"
"
" For cursor moving in insert mode(Not recommended)
"inoremap <expr><Left> neocomplcache#close_popup() . "\<Left>"
"inoremap <expr><Right> neocomplcache#close_popup() . "\<Right>"
"inoremap <expr><Up> neocomplcache#close_popup() . "\<Up>"
"inoremap <expr><Down> neocomplcache#close_popup() . "\<Down>"
" Or set this.
"let g:neocomplcache_enable_cursor_hold_i = 1
" Or set this.
"let g:neocomplcache_enable_insert_char_pre = 1
"
" AutoComplPop like behavior.
"let g:neocomplcache_enable_auto_select = 1
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplcache_enable_auto_select = 1
"let g:neocomplcache_disable_auto_complete = 1
"inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
"
" Enable omni completion.
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
"
" Enable heavy omni completion.
if !exists('g:neocomplcache_force_omni_patterns')
let g:neocomplcache_force_omni_patterns = {}
endif
let g:neocomplcache_force_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
let g:neocomplcache_force_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.cpp = '[^.[:digit:]*\t]\%(\.\|->\)\|\h\w*::'
"
" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplcache_force_omni_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
" 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_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
"
" If you want to use a different collection of snippets than the built-in
" ones, then you can set a path to the snippets with the
" g:neosnippet#snippets_directory variable (e.g Honza's Snippets)
"
" But if you enable g:neosnippet#enable_snipmate_compatibility, neosnippet
" will load snipMate snippets from runtime path automatically.
"
" Enable snipMate compatibility feature.
let g:neosnippet#enable_snipmate_compatibility = 1
"
" Tell Neosnippet about the other snippets
let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: Wallance")
call append(line(".")+2, "\# mail: halyx@126.com")
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\#########################################################################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: Wallance")
call append(line(".")+2, " > Mail: halyx@126.com ")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if &filetype == 'cpp'
call append(line(".")+6, "#include <iostream>")
call append(line(".")+7, "\#include <algorithm>")
call append(line(".")+8, "\#include <cmath>")
call append(line(".")+9, "\#include <cstdio>")
call append(line(".")+10, "\#include <cstring>")
call append(line(".")+11, "\#include <cstdlib>")
call append(line(".")+12, "\#include <list>")
call append(line(".")+13, "\#include <set>")
call append(line(".")+14, "\#include <stack>")
call append(line(".")+15, "\#include <map>")
call append(line(".")+16, "\#include <queue>")
call append(line(".")+17, "\#include <string>")
call append(line(".")+18, "\#include <vector>")
call append(line(".")+19, "\#include <cctype>")
call append(line(".")+20, "using namespace std;")
call append(line(".")+21, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include <stdio.h>")
call append(line(".")+7, "")
endif
if &filetype == 'py'
call append(line(".")+6, "\#!/usr/bin/python")
endif
if &filetype == 'pl'
call append(line(".")+6, "\#!/usr/bin/perl")
endif
if &filetype == 'sed'
call append(line(".")+6, "\#!/bin/sed -f")
endif
if &filetype == 'awk'
call append(line(".")+6, "\#!/usr/bin/awk")
endif
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc
"
" Omnicppcomplete
set completeopt=menu,menuone
let OmniCpp_MayCompleteDot=1 " 打开.操作符
let OmniCpp_MayCompleteArrow=1 "打开 -> 操作符
let OmniCpp_MayCompleteScope=1 "打开 :: 操作符
let OmniCpp_NamespaceSearch=1 "打开命名空间
let OmniCpp_GlobalScopeSearch=1
let OmniCpp_DefaultNamespace=["std"]
let OmniCpp_ShowPrototypeInAbbr=1 "打开显示函数原型
let OmniCpp_SelectFirstItem = 2 "自动弹出时自动跳至第一个
set tags+=/usr/include/tags
set tags+=/usr/include/tags_stl
参考文档:
github.com
网上已有讲解VIM配置的博客,一并表示感谢,因为参考的文章比较多,就不一一列举了,请谅解。
重点参考的是SPF13和ma6174的两个人配置,这两个人的VIM配置用着感觉一直不错,我就来了个结合。