分享一下我的的Vim配置文件

    強烈擁護開源精神,高舉開源大旗,今天我就分享下我本身結合網上還有本身實際使用配的vimrc,能夠給各位參考下,不要見笑哈,具體說明我在rc裏寫的也很詳細,能夠具體看下,也但願能夠借這個機會能多認識認識幾個Vimer們.css

    PS: 好比說轉移工做環境或者切換主機,比較便捷到作法就是安裝好vim以後,一遍git clonehttps://github.com/gmarik/vundle.git ~/.vim/bundle/vundle,將vundle插件裝好以後,一陣BundleInstall,便可完美切換到你之前使用到Vim環境,十分方便。另外主題下載以後拷貝到.vim/colors以後便可適配,地址在.vimrc內部,還有monaco字體配置能夠直接git clone https://github.com/jiyinyiyong/monaco-font.git/html

    

"========================================  
" File Name: .vimrc  
" Author: Ricky.K 
" Description: Vim配置文檔  
" Date: 2014.7.12  
"========================================  

let mapleader = ','  
let g:mapleader = ','  

"==========================================
" General Settings
"==========================================

" 開啓語法高亮  
syntax enable  

" 開啓語法高亮
syntax on  

" 設置字體  
set guifont=Monaco\ 12

" 設置歷史記錄條數  
set history=2000  

" 檢測文件類型  
filetype on  

" 針對不一樣的文件,採用不一樣的縮進方式  
filetype indent on  

" 容許插件  
filetype plugin on  

" 啓動自動補全
filetype plugin indent on

" 文件修改以後自動讀入
set autoread

" 啓動後不顯示提示
"set shortmess=atI

" 備份,到另外一個位置. 防止誤刪, 目前是取消備份
"set backup
"set backupext=.bak
"set backupdir=/tmp/vimbk/

" 設置取消備份,禁止臨時文件生成  
set nobackup  
set noswapfile  

" create undo file
set undolevels=1000 " how many undos
set undoreload=10000 " number of lines to save for undo
if v:version >= 730
    set undofile     " keep a persistent backup file
    set undodir=/tmp/vimundo/
endif

"set wildignore=*.swp,*.bak,*.pyc,*.class,.svn

" 顯示當前橫豎線  
"set cursorline  
"set cursorcolumn  

" 設置退出Vim以後內容顯示在終端屏幕,能夠用於查看和複製
" 好處:誤刪什麼,若是之前屏幕打開能夠用來找回
" set t_ti= t_te=

" 設置在Vim中能夠使用鼠標,防止終端沒法拷貝  
set mouse=a  

" 修復ctrl+m多光標操做選擇的bug,可是改變了ctrl+v進行字符選中將包含光標下的字符
" set selection=inclusive
" set selectmode=mouse,key

" no errors sound
set title " change ther terminal's title
set novisualbell " don't beep
set noerrorbells " don't beep
set t_vb=
set tm=500

" remember info about open buffers on close
set viminfo^=%

" for regular expression turn magic on
set magic

" configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

" FuzzyFinder and ctrlp couldn't auto change dir you must manual add cd in
" command mode, so add this command to auto change current dir for these
" plugins
" set autochdir

"==========================================
" Display Settings
"==========================================
"
" 顯示當前行號和列號
set ruler

" 在狀態欄顯示正在輸入的命令
set showcmd

" 左下角顯示當前Vim模式
set showmode

" 光標移動至少保留的行數
"set scrolloff=7

" 命令行(在狀態行下)的高度,默認爲1,這裏是2
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P

" 老是顯示狀態欄(Powerline須要2行)  
set laststatus=2  

" 顯示行號  
set number  

" 指定不折行
set nowrap  

" 設置代碼匹配,包括括號匹配狀況  
set showmatch  

" how many tenths of a second to blink when matching brackets
" setmatchtime=2

" 開啓及時搜索(is)  
set incsearch  

" 設置搜索高亮(hlsearch)  
set hls  

" 設置搜索時忽略大小寫  
set ignorecase  

" 當搜索的時候嘗試smart  
set smartcase  

" 設置代碼摺疊
"set foldenable
" 摺疊方法
" manual 手工摺疊
" indent 縮進摺疊
" expr 表達式摺疊
" syntax 語法摺疊
" diff 對沒有更改的文件摺疊
" marker 標記摺疊
"set foldmethod=indent
"set foldlevel=99

" 設置C/C++方式自動對齊  
set autoindent  
set cindent  
set smartindent  

" 設置tab寬度  
set tabstop=4  

" 設置自動對齊空格數  
set shiftwidth=4  

" 按退格鍵時能夠一次刪除4個空格
"set softtabstop=4

 " 編輯的時候將全部的tab設置爲空格(expandtab)  
 set et  

 " 使用Backspace直接刪除tab  
 set smarttab  

" 不在單詞中間折行  
set lbr  

 " 縮進時取整use multiple of shiftwidth when indenting with '<' and '>'
 " set shiftround

 " a buffer becomes hidden when it is abandoned
 " set hidden
 " set wildmode=list:longest
 " set ttyfast

 " 00x增減數字時使用十進制
 "set nrformats=
 "
 "==========================================
 " FileEncode Settings
 "==========================================

 " 設置編碼方式  
 set encoding=utf-8  

 " 設置打開文件的編碼格式  
 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1  

 set helplang=cn 

 " 只對終端影響(默認)
 set termencoding=utf-8

 " use UNIX as the standard file type
 set ffs=unix,dos,mac

" 如遇Unicode值大於255的文本,沒必要等到空格再折行。
set formatoptions+=m

" 合併兩行中文時,不在中間加空格:
set formatoptions+=B

"==========================================
" Other Settings
"==========================================

 "autocmd! bufwritepost _vimrc source %    " .vimrc修改以後自動加載(Windows)
 "autocmd! bufwritepost .vimrc source %    " .vimrc修改以後自動加載(Linux)

 " 自動補全配置讓Vim補全菜單行爲跟IDE一致
 set completeopt=longest,menu

 " 加強模式中的命令行自動完成操做
 set wildmenu

 " ignore compiled files
 " set wildignore=*.o,*~,*.pyc,*.class

"離開插入模式後自動關閉預覽窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif

"回車即選中當前項
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"

"上下左右鍵的行爲 會顯示其餘信息
inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"

" if this not work ,make sure .viminfo is writable for you
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

"==========================================
" HotKey Settings
"==========================================
"
" 去掉搜索高亮
"noremap <silent><leader>/ :nohls<CR>
map <leader>/ :nohls<CR>

map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove

" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/

" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>

" 手動刷新tags(含cscope)
nmap tg :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q *<CR>:set tags+=./tags<CR>:!cscope -Rbq<CR>:cs add ./cscope.out .<CR>

" 切換buffer
nnoremap [b :bp<CR>
nnoremap ]b :bn<CR>

" cscope設置
if has("cscope")
    set csprg=/usr/bin/cscope   " 制定cscope命令
    set csto=0                  " ctags查找順序,0表示先cscope數據庫再標籤文件,1表示先標籤文件愛
    set cst                     " 同時搜索tag文件和cscope數據庫
    set cscopequickfix=s-,c-,d-,i-,t-,e-  "使用QucikFix窗口來顯示cscope查找結果
    set nocsverb
    if filereadable("cscope.out")  "若是當前目錄下有cscope.out則加載進Vim
        cs add cscope.out
    elseif $CSCOPE_DB != ""       "不然只要環境變量不爲空就添加制定的數據庫到Vim
        cs add $CSCOPE_DB
    endif
    set csverb
endif
"map <F4>:!cscope -Rbq<CR>:cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
" 查找符號
nmap <leader>css :cs find s <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
" 查找定義
nmap <leader>csg :cs find g <C-R>=expand("<cword>")<CR><CR>
" 查找被這個函數調用的函數
nmap <leader>csd :cs find d <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
" 查找調用這個函數的函數
nmap <leader>csc :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR><CR>
" 查找這個字符串
nmap <leader>cst :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR><CR>
" 查找這個egrep匹配模式
nmap <leader>cse :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR><CR>
" 查找這個文件
nmap <leader>csf :cs find f <C-R>=expand("<cfile>")<CR><CR>
" 查找include這個文件的文件
nmap <leader>csi :cs find i <C-R>=expand("<cfile>")<CR><CR> :copen<CR><CR>

" 設定是否使用QuickFix來顯示結果
set cscopequickfix=s-,c-,d-,i-,t-,e-

" QuickFix open and close
nnoremap <F11> :copen<CR>
nnoremap <F12> :cclose<CR>

" QucikFix next and prev
nnoremap <F9> :cn<CR>
nnoremap <F10> :cp<CR>

"==========================================
" Theme Settings
"==========================================

" Set extra options when running in GUI mode
"if has("gui_running")
"    set guifont=Monaco\ 12
"    set guioptions-=T
"    set guioptions+=e
"    set guioptions-=r
"    set guioptions-=L
"    set guitablabel=%M\ %t
"    set showtabline=1 
"    set linespace=2 
"    set noimd   
"    set t_Co=256
"endif

" 設置主題  
set background=dark
colorscheme molokai  
"colorscheme solarized
set t_Co=256

" 添加水平滾動條  
"set guioptions+=b  

" 取消菜單欄和導航欄  
set guioptions-=m  
set guioptions-=T  

" 去除左右兩邊滾動條
set go-=r
set go-=L

" 設置水平行數和豎直列數  
set lines=35  
set columns=99  

" 使pathogen生效(插件管理器,只需將插件放入bundle,將pathogen.vim放入autoload便可)  
"execute pathogen#infect()  
"
"==========================================
" Vundle Settings
"==========================================

 " 關閉vi的一致性模式,避免之前版本的一些Bug和侷限  
set nocompatible  

filetype off " Vundle必需要求使用filetype off,若是不設置該選項,UltiSnips沒法使用  

if has('win32') || has('win64')
    set rtp+=$HOME/vimfiles/vundle
    call vundle#rc('$HOME/vimfiles/bundle/')
else
   set rtp+=~/.vim/bundle/vundle  
   call vundle#rc()  
endi

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

" My bundles here:  
" original repos on GitHub  
Bundle 'tpope/vim-fugitive'  
Bundle 'Lokaltog/vim-easymotion'  

" 自動補全單引號,雙引號等
Bundle 'Raimondi/delimitMate'

" 快速加入修改環繞字符
Bundle 'tpope/vim-surround'
" for repeat -> enhance surround.vim, . to repeat command
Bundle 'tpope/vim-repeat'

" 多光標編輯 (該插件的ctrl-p能夠正常使用,當到達最後一個的時候ctrlp纔會起做用)
Bundle 'terryma/vim-multiple-cursors'

" 對括號等進行光標的控制輔助  
"Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}  
"Bundle 'tpope/vim-rails.git'  
Bundle 'Valloric/ListToggle'  
Bundle 'L9'  

" vim-scripts repos  
Bundle 'a.vim'  
Bundle 'grep.vim'
"Bundle 'easytags.vim'  
"Bundle 'c.vim'  
" 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'  

"==========================================
" ctrlp settings  
"==========================================
Bundle 'kien/ctrlp.vim'  
"let g:ctrlp_map = '<leader>p'
"let g:ctrlp_cmd = 'CtrlP'
"map <leader>f :CtrlPMRU<CR>
"set wildignore+=*/tmp/*,*.so,*.swp,*.zip     " MacOSX/Linux
"let g:ctrlp_custom_ignore = {
"    \ 'dir':  '\v[\/]\.(git|hg|svn|rvm)$',
"    \ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz)$',
"    \ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
"    \ }
let g:ctrlp_custom_ignore = {
   \ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz|lib|out|png|img|bak|db|o)'
    \ }
" 在每次進行切換分支或者從新設定custome_ignore選項的時候,必須手動清除CtrlP的緩存,
" 也能夠使用下句不讓它進行緩存處理,但掃描時間會比較耗時
"let g:ctrlp_use_caching = 0
let g:ctrlp_working_path_mode=0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=15
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
nnoremap <leader>b :CtrlPBuffer<CR>
nnoremap <leader>d :CtrlPDir<CR>

"==============================================================
" ctrlp-funky settings  ctrlp插件 - 不用ctag進行函數快速跳轉
"==============================================================
Bundle 'tacahiroy/ctrlp-funky'
"nnoremap <Leader>fu :CtrlPFunky<Cr>
nnoremap <Leader>f :CtrlPFunky<Cr>
" narrow the list down with a word under cursor
"nnoremap <Leader>fU :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
let g:ctrlp_funky_syntax_highlight = 1
let g:ctrlp_extensions = ['funky']

"==========================================
" nerdcommenter settings  快速註釋
"==========================================
Bundle 'scrooloose/nerdcommenter'
" 註釋與代碼之間留存的空格數
let g:NERDSpaceDelims = 1

"==========================================
" Airline settings
"==========================================
"Bundle 'bling/vim-airline'
"Bundle 'bling/vim-bufferline'
"if !exists('g:airline_symbols')
"let g:airline_symbols = {}
"endif
"let g:airline_left_sep = '▶'
"let g:airline_left_alt_sep = '❯'
"let g:airline_right_sep = '◀'
"let g:airline_right_alt_sep = '❮'
"let g:airline_symbols.linenr = '¶'
"let g:airline_symbols.branch = '⎇'
"" 開啓tabline
"let g:airline#extensions#tabline#enabled = 1
"" tabline中當前buffer兩端的分隔符
"let g:airline#extensions#tabline#left_sep = ' '
"" tabline爲激活的buffer的兩端字符
"let g:airline#extensions#tabline#left_alt_sep = '|'
"" tabline中buffer顯示編號
"let g:airline#extensions#tabline#buffer_nr_show = 1
"let g:airline#extensions#buffline#enabled = 1
"let g:airline#extensions#bufferline#overwrite_variables = 1
"" airline主題
"let g:airline_theme = 'powerlineish' 

"括號顯示加強
"Bundle 'kien/rainbow_parentheses.vim'
"let g:rbpt_colorpairs = [
"    \ ['brown',       'RoyalBlue3'],
"    \ ['Darkblue',    'SeaGreen3'],
"    \ ['darkgray',    'DarkOrchid3'],
"    \ ['darkgreen',   'firebrick3'],
"    \ ['darkcyan',    'RoyalBlue3'],
"    \ ['darkred',     'SeaGreen3'],
"    \ ['darkmagenta', 'DarkOrchid3'],
"    \ ['brown',       'firebrick3'],
"    \ ['gray',        'RoyalBlue3'],
"    \ ['black',       'SeaGreen3'],
"    \ ['darkmagenta', 'DarkOrchid3'],
"    \ ['Darkblue',    'firebrick3'],
"    \ ['darkgreen',   'RoyalBlue3'],
"    \ ['darkcyan',    'SeaGreen3'],
"    \ ['darkred',     'DarkOrchid3'],
"    \ ['red',         'firebrick3'],
"    \ ]
"let g:rbpt_max = 40
"let g:rbpt_loadcmd_toggle = 0
"au VimEnter * RainbowParenthesesToggle
"au Syntax * RainbowParenthesesLoadRound
"au Syntax * RainbowParenthesesLoadSquare
"au Syntax * RainbowParenthesesLoadBraces


" 主題 solarized 
Bundle 'altercation/vim-colors-solarized'
"let g:solarized_termcolors=256
let g:solarized_termtrans=1
let g:solarized_contrast="normal"
let g:solarized_visibility="normal"

" 主題 molokai 
Bundle 'tomasr/molokai'

"==========================================
" TagList settings
"==========================================
Bundle 'taglist.vim'  
" increase the width of the taglist window  
"let Tlist_WinWidth=20  
" 自動打開TagList的window  
let Tlist_Auto_Open=0  
" 當只剩下Tlist的時候自動關閉  
let Tlist_Exit_OnlyWindow=1  
" 打開tags用單擊  
let Tlist_Use_SingleClick=1  
" close tag folders for inactive buffers  
let Tlist_File_Fold_Auto_Close=1  
" show the fold indiactor column in the taglist window  
let Tlist_Enable_Fold_Column=1  
" 自動更新TagList包含最新編輯的文件  
let Tlist_Auto_Update=1  
" 顯示一個文件的tag  
let Tlist_Show_One_File=1  
" 在右側顯示窗口  
let Tlist_Use_Right_Window=1  
" 按照名稱排序  
let Tlist_Sort_Type="name"  
" 讓TagList始終解釋文件中的tag,無論TagList窗口有沒有打開  
let Tlist_Process_File_Always=1  
" 設置leader鍵  
nnoremap <leader>tl :TlistToggle<CR>  

"==========================================
" YouCompleteMe settings
"==========================================
Bundle 'Valloric/YouCompleteMe'  
"let g:ycm_key_list_select_completion=['<c-n>']
"let g:ycm_key_list_previous_completion=['<c-p>']
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py'  
let g:ycm_collect_indentifiers_from_tags_files=1  
let g:ycm_seed_identifiers_with_syntax=1  
" 避免YCM每次加載都對用戶提示是否加載  
let g:ycm_confirm_extra_conf=0  
let g:ycm_autoclose_preview_window_after_completion=1  
let g:ycm_complete_in_comments = 1  "在註釋輸入中也能補全
let g:ycm_complete_in_strings = 1   "在字符串輸入中也能補全
let g:ycm_collect_identifiers_from_comments_and_strings = 1   "註釋和字符串中的文字也會被收入補全
" 跳到定義或聲明  
nnoremap <F2> :YcmCompleter GoToDefinitionElseDeclaration<CR>  
" 強制進行編譯  
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>  

"==========================================
" Syntastic settings
"==========================================
Bundle 'scrooloose/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++'  
let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++'  
"set error or warning signs  
let g:syntastic_error_symbol = ''  
let g:syntastic_warning_symbol = ''  
"whether to show balloons  
let g:syntastic_enable_balloons = 1  
let g:syntastic_always_populate_loc_list = 1  

"==========================================
" ListToggle settings
"==========================================
let g:lt_location_list_toggle_map = '<leader>l'  
let g:lt_quickfix_list_toggle_map = '<leader>q'  


"==========================================
" NERDtree settings
"==========================================
Bundle 'scrooloose/nerdtree'  
let NERDTreeWinPos='left'  
let NERDTreeHighlightCursorline=1
nnoremap <leader>n :NERDTreeToggle<CR>  
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | q | endif  

"==========================================
" miniBufExpl settings
"==========================================
"Bundle 'fholgado/minibufexpl.vim'
"let g:miniBufExplMapWindowNavVim = 1
"let g:miniBufExplMapWindowNavArrows = 1
"let g:miniBufExplMapCTabSwitchBufs = 1
"let g:miniBufExplModSelTarget = 1
""解決FileExplorer窗口變小問題
"let g:miniBufExplForceSyntaxEnable = 1
"let g:miniBufExplorerMoreThanOne=2
"let g:miniBufExplCycleArround=1
"" 默認方向鍵左右能夠切換buffer
"nnoremap <TAB> :MBEbn<CR>
"nnoremap <s-TAB> :MBEbp<CR>
"noremap <leader>bn :MBEbn<CR>
"noremap <leader>bp :MBEbp<CR>
"noremap <leader>bd :MBEbd<CR>

"==========================================
" FuzzyFinder settings
"==========================================
"Bundle 'FuzzyFinder'  
"nnoremap <leader>f :FufFile<CR>  
"nnoremap <leader>b :FufBuffer<CR>  
"nnoremap <leader>d :FufDir<CR>  

"==========================================
" UltiSnips settings
"==========================================
Bundle 'SirVer/ultisnips'  
Bundle 'honza/vim-snippets'
let g:UltiSnipsExpandTrigger = "<c-j>"
let g:UltiSnipsJumpForwardTrigger = "<c-j>"
let g:UltiSnipsJumpBackwardTrigger = "<c-k>"
" 定義存放代碼片斷的文件夾 .vim/additional_snippets下,使用自定義和默認的,將會的到全局,有衝突的會提示
let g:UltiSnipsSnippetDirectories=["additional_snippets", 'UltiSnips']

"==========================================
" closetag settings 自動補全html/xml標籤
"==========================================
"Bundle 'docunext/closetag.vim'
"let g:closetag_html_style=1

"==========================================
" Markdown settings
"==========================================
"Bundle 'plasticboy/vim-markdown'
"let g:vim_markdown_folding_disabled=1

"==========================================
" Tagbar settings
"==========================================
Bundle 'majutsushi/tagbar'  
nnoremap <leader>tb :Tagbar<CR>  
let g:tagbar_autofocus = 1

"==========================================
" A settings
"==========================================
nnoremap <F4> :A<CR>  

"==========================================
" Powerline settings
"==========================================
Bundle 'Lokaltog/vim-powerline'  
let g:Powerline_symbolsa = 'fancy'  
let g:Powerline_cache_enabled = 1  

""let g:session_autoload='yes'  
""let g:session_autosave='yes'  

" 由於Vundle須要關閉filetype,而以後的插件若是想要正常使用,必需要打開filetype
" 因此必須確保全部插件的加載過程在以前已經所有添加完畢
filetype on             

" 參考連接:  
" amix vimrc模板地址參考:amix.dk/vim/vimrc.html  
" k-vim https://github.com/wklken/k-vim
相關文章
相關標籤/搜索