vim 高級使用技巧

前言:逃離windows有很長時間了,特別是當今android盛行的時代,咱們沒有理由不選擇ubuntu做爲編譯開發android之首選。其實操做系統只是咱們使用的一個工具,javascript

windows也好linux也罷,本身用的好纔是真的好。可是好的開發工具能讓咱們事半功倍。css

 

  先談談個人編程開發工具之路,source insight3.5這都是剛工做必備之工具,簡直就代碼閱讀開發之神器。但有一個缺點就是調試編譯非常不方便。vs編程的高富帥,編程調試非常好用,界面至關的友好。基本上windows程序開發編譯調試面面俱到全方位無死角。可是咱們嵌入式開發大部分都是linux下的,這高大上的工具雖然眼饞,但是基本上高級功能咱們只能想一想,仍是洗洗睡吧。html

   

  俗話說工欲善其事必先利其器,那就讓咱們來一塊兒學習linux下的開發工具吧!目前我使用的是ubuntu,但基本上linux系統都差很少,很明顯的標誌就是都有Terminal。java

基於命令行的操做,vim更是linux的必備工具。說了半天咱們進入主題吧vim編程環境搭建使用,大工程的閱讀開發調試。node

首先咱們仍是先來說一下搭建:python

sudo apt-get install vim exuberant-ctags cscope global;  (ubuntu14.04及以上版本執行便可,如下版本請先執行如下操做)jquery

sudoadd-apt-repository ppa:fcwu-tw/ppa;linux

sudoapt-get update; android

sudo apt-get install vim;nginx

 

  若是你對上面這些工具不熟悉請google, bing, baidu。有了這些工具咱們仍是隻能簡單的操做,對工程的閱讀開發仍是遠遠不夠的。因此咱們要配置vim,加入一些vim plugin,有兩個文件.vimrc .vimrc.bundles 我配置的腳本首次須要下載請執行 :BundleInstall 安裝腳本,下載完了你就可使用它的強大功能了。你能夠先看腳本中的中文註釋,瞭解咱們使用了那些快捷鍵,下篇我將介紹一下經常使用功能快捷鍵及大工程閱讀開發。讓你成爲真正的鍵盤黨,擺脫鼠標手。

 

廢話很少說了直接上配置腳本vim 配置:

.vimrc(保存文件名放到你$HOME目錄)

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" settings for vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" This file contains some boilerplate settings for vim's cscope interface,
" plus some keyboard mappings that I've found useful.
"
" USAGE:
" -- vim 6:     Stick this file in your ~/.vim/plugin directory (or in a
"               'plugin' directory in some other directory that is in your "
"               'runtimepath'.  "
" Jason Duell   'yistn@163.com     2013/3/13
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""multi-encodingi setting多語言編碼轉換""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("multi_byte")
"set bomb
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,gb2312,gbk,big5,euc-jp,euc-kr
set encoding=utf8
" CJK environment detection and corresponding setting
if v:lang =~ "^zh_CN"
" Use cp936 to support GBK, euc-cn == gb2312
set encoding=cp936
set termencoding=cp936
set fileencoding=cp936
elseif v:lang =~ "^zh_TW"
" cp950, big5 or euc-tw
" Are they equal to each other?
set encoding=big5
set termencoding=big5
set fileencoding=big5
elseif v:lang =~ "^ko"
" Copied from someone's dotfile, untested
set encoding=euc-kr
set termencoding=euc-kr
set fileencoding=euc-kr
elseif v:lang =~ "^ja_JP"
" Copied from someone's dotfile, untested
set encoding=euc-jp
set termencoding=euc-jp
set fileencoding=euc-jp
endif
" Detect UTF-8 locale, and replace CJK setting if needed
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
endif
else
echoerr "Sorry, this version of (g)vim was not compiled with multi_byte"
endif


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""" Initial Plugin 加載插件""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" install Vundle bundles
if filereadable(expand("~/.vimrc.bundles"))
  source ~/.vimrc.bundles
endif


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""vim 樣式配置""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 基礎配置設置
filetype on                   "檢測文件類型
filetype indent on           "針對不一樣的文件類型採用不一樣的縮進格式
filetype plugin on           "容許插件
filetype plugin indent on     "啓動自動補全


"autocmd! bufwritepost _vimrc source %     "vimrc文件修改以後自動加載。 windows。
"autocmd! bufwritepost .vimrc source %     "vimrc文件修改以後自動加載。 linux。
syntax enable "開啓代碼高亮
syntax on "打開高亮
set completeopt=longest,menu "自動補全配置,讓Vim的補全菜單行爲與通常IDE一致(參考VimTip1228)
"set relativenumber number   "相對行號,可用Ctrl+n在相對/絕對行號間切換
set cursorcolumn             "突出顯示當前列,可用Ctrl+m切換是否顯示
"set cursorline               "突出顯示當前行,可用Ctrl+m切換是否顯示
set history=3000             "history存儲長度
set nocompatible             "非兼容vi模式,避免之前版本的一些bug和侷限
set nu "顯示行數 
set shiftwidth=4             "換行時行間交錯使用4空格
set cindent shiftwidth=4     "自動縮進4空格
set tabstop=4                 "讓一個tab等於4個空格
set vb t_vb=
set showmatch                 "顯示括號配對狀況
set autoread                 "當文件在外部被改變時,Vim自動更新載入
set nowrap                   "設置不自動換行
set writebackup               "設置無備份文件
set nobackup "取消備份。 視狀況本身改
set noswapfile "關閉交換文件
set showmode "開啓模式顯示  
set cmdheight=1               "命令部分高度爲1 
set shortmess=atI             "啓動的時候不顯示那個援助索馬里兒童的提示
set t_ti= t_te=               "退出vim後,內容顯示在終端屏幕 設置 退出vim後,內容顯示在終端屏幕, 能夠用於查看和複製好處:誤刪什麼的,若是之前屏幕打開,能夠找回
" 去掉輸入錯誤的提示聲音
set title                     "change the terminal's title
set novisualbell             "don't beep
set noerrorbells             "don't beep
set t_vb=
set tm=500


"set backup                   "備份
"set backupext=.bak
"set backupdir=/tmp/vimbk/
set mat=4                     "Blink times every second when matching brackets
set hidden                   "A buffer becomes hidden when it is abandoned
set wildmode=list:longest
set ttyfast


set wildignore=*.swp,*.bak,*.pyc,*.class
set scrolloff=3               "至少有3行在光標所在行上下


set selection=old
set selectmode=mouse,key
set viminfo^=%                   "Remember info about open buffers on close
set viminfo+=! " 保存全局變量
set magic                       "正則表達式匹配形式
set backspace=eol,start,indent   "Configure backspace so it acts as it should act
"set backspace=indent,eol,start whichwrap+=<,>,[,] "容許退格鍵的使用
"set iskeyword+=_,$,@,%,#,-   "帶有以下符號的單詞不要被換行分割 
set iskeyword+=_,$,@,%,#   "帶有以下符號的單詞不要被換行分割 
" 字符間插入的像素行數目
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}   set filetype=mkd   "markdown配置


"set go=             "不要圖形按鈕  
set cul             "高亮光標所在行
autocmd InsertEnter * se cul "用淺色高亮當前行  
set ruler           "顯示標尺  
set showcmd         "輸入的命令顯示出來,看的清楚些  


" Set extra options when running in GUI mode
if has("gui_running")
    set guifont=Monaco:h14
    set guioptions-=T
    set guioptions+=e
    set guioptions-=r
    set guioptions-=L
    set guitablabel=%M\ %t
    set showtabline=1
    set linespace=4
    set noimd
    set t_Co=256
else
"set guifont=Courier_New:h10:cANSI  " 設置字體  
set guifont=Fixedsys:h12:cANSI" 設置字體  


endif


"設置標記一列的背景顏色和數字一行顏色一致
hi! link SignColumn   LineNr
hi! link ShowMarksHLl DiffAdd
hi! link ShowMarksHLu DiffChange
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}  "狀態行顯示的內容
set statusline+=%f       "不顯示工具條
ret laststatus=2     "啓動顯示狀態行(1),老是顯示狀態行(2)  


" max memory (in KiB) used for pattern matching
"set maxmempattern=100
"set foldenable     "容許摺疊  
"set foldmethod=manual   "手動摺疊 


" 選中模式 Ctrl+c 複製選中的文本
"vnoremap <c-c> "+y
" 普通模式下 Ctrl+c 複製文件路徑
"nnoremap <c-c> :let @+ = expand('%:p')<cr>


" Shift + Insert 插入系統剪切板中的內容
"noremap <S-Insert> "+p
"vnoremap <S-Insert> d"+P
"inoremap <S-Insert> <esc>"+pa
"inoremap <C-S-Insert> <esc>pa


"set ignorecase "搜索時忽略大小寫 
set hlsearch                 "高亮顯示結果
"set nohlsearch "關閉搜索高亮  
set incsearch                 "在輸入要搜索的文字時,vim會實時匹配
" 有一個或以上大寫字母時仍大小寫敏感
set smartcase     "ignore case if search pattern is all lowercase, case-sensitive otherwise
"autocmd BufEnter * cd %:c:p:h   "設置狀態欄


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" F1 - F6 設置
" F1 廢棄這個鍵,防止調出系統幫助
" F2 行號開關,用於鼠標複製代碼用
" F3 換行開關
" F4 調出listbar函數列表
" F5 粘貼模式paste_mode開關,用於有格式的代碼粘貼
" F6 語法開關,關閉語法能夠加快大文件的展現
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


" I can type :help on my own, thanks.  Protect your fat fingers from the evils of <F1>
noremap <F1> <Esc>"
nnoremap <F2> :set nonumber! number?<CR>
nnoremap <F3> :set wrap! wrap?<CR>
nmap <silent> <F4> :TagbarToggle<CR> "按下F4就能夠呼出文件的函數列表及變量
set pastetoggle=<F5>             "when in insert mode, press <F5> to go to
                                "paste mode, where you can paste mass data
                                "that won't be autoindented
au InsertLeave * set nopaste
nnoremap <F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>


" disbale paste mode when leaving insert mode


"Smart way to move between windows 分屏窗口移動
"則能夠用<C-h,j,k,l>切換到上下左右的窗口中去,就像:
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l


"Treat long lines as break lines (useful when moving around in them)
"se swap以後,同物理行上線直接跳
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
" Go to home and end using capitalized directions
noremap H ^
noremap L $


" 命令行模式加強,ctrl - a到行首, -e 到行尾
cnoremap <C-a> <Home>
cnoremap <C-e> <End>


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


" --------tab/buffer相關


"Use arrow key to change buffer"
noremap <left> :bp<CR>
noremap <right> :bn<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>/


"共享剪貼板  
set clipboard+=unnamed 


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("autocmd")
filetype plugin indent on   "根據文件進行縮進 
    augroup vimrcEx
        au!
        autocmd FileType text setlocal textwidth=78
        autocmd BufReadPost *
                    \ if line("'\"") > 1 && line("'\"") <= line("$") |
                    \ exe "normal! g`\"" |
                    \ endif
    augroup END
"autocmd Filetype c      set omnifunc=ccomplete#Complete
"autocmd Filetype html   set omnifunc=htmlcomplete#CompleteTags
"autocmd Filetype xml    set omnifunc=xmlcomplete#CompleteTags
"autocmd Filetype python set omnifunc=pythoncomplete#CompleteTags
"autocmd Filetype tex    set omnifunc=syntaxcomplete#Complete
autocmd FileType c,cpp set shiftwidth=4 | set expandtab "每次在編輯c文件時,它的自動縮進爲4個空格;當你在插入模式下使用CTRL-D、CTRL-T縮進時,它也會調整4個空格的縮進;當你按TAB鍵時,它將會插入8個空格
    "set cinoptions={0,1s,t0,n,p2s,(03s,=.5s,>1s,=1s,:1s
    "智能縮進,相應的有cindent,官方說autoindent能夠支持各類文件的縮進,可是效果會比只支持C/C++的cindent效果會差一點,但筆者並無看出來
    set ai!                     "設置自動縮進
    set smartindent             "智能自動縮進
    set noautoindent             "自動對齊 設置自動縮進:即每行的縮進值與上一行相等;使用 noautoindent 取消設置
else
    "智能縮進,相應的有cindent,官方說autoindent能夠支持各類文件的縮進,可是效果會比只支持C/C++的cindent效果會差一點,但筆者並無看出來
    set ai!                     "設置自動縮進
    set smartindent             "智能自動縮進
    set noautoindent             "自動對齊 設置自動縮進:即每行的縮進值與上一行相等;使用 noautoindent 取消設置
endif " has("autocmd")


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""設置cscope ctags"配置""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope") 
 
    """"""""""""" Standard cscope/vim boilerplate 
 
if filereadable("GTAGS")
set csprg=gtags-cscope
" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t' 
" check cscope for definition of a symbol before checking ctags: set to 1 
" if you want the reverse search order. 
set csto=0 
set cst  
set nocsverb 
"cs reset
"let Gtags_Auto_Map = 1
cs add GTAGS $PWD
endif 


"    " add any cscope database in current directory 
    if filereadable("cscope.out") 
set csprg=cscope
set csto=0 
set cst  
set nocsverb 
        cs add cscope.out   
    " else add the database pointed to by environment variable  
    elseif $CSCOPE_DB != "" 
        cs add $CSCOPE_DB 
    endif 


set csverb   
"    " show msg when any other cscope db added 
    set cscopeverbose
endif


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>


map <F9> :call Do_CsGTag()<CR>
function Do_CsGTag()
    let dir = getcwd()
if filereadable("filenametags")
            let csoutdeleted=delete("./"."filenametags")
        if(csoutdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the filenametags" | echohl None
            return
        endif
endif


silent! execute"!find `pwd` -name '*.h' -o -name '*.c++' -o -name '*.cc' -o -name '*.cp' -o -name '*.cpp' -o -name '*.cxx' -o -name '*.h++' -o -name '*.hh' -o -name '*.hp' -o -name '*.hpp' -o -name '*.hxx' -o -name '*.C' -o -name '*.H' -o -name '*.ipp' -o -name '*.c' -o -name '*.js' -o -name '*.java' -o -name '*.idl' -o -name '*.mak' -o -name '*.mk' -o -name '[Mm]akefile' -o -name 'GNUmakefile' -o -name '*.pl' -o -name '*.pm' -o -name '*.plx' -o -name '*.perl' -o -name '*.cmake' -o -name '*.y' -o -name '*.sh' -o -name 'CMakeList*.txt'> gtags.files"
silent! execute "!gtags -qv -f `pwd`/gtags.files"
"silent! execute "!ctags -R --languages=+c,c++,java,javascript,make,perl,yacc,sh --langmap=c:+.x,c++:+.inl,make:+.mk.cmake --c-kinds=+px --c++-kinds=+px --fields=+afmikKlnsStz --extra=+q --exclude=lex.yy.cc --exclude=copy_lex.yy.cc"


"execute "cs add GTAGS $PWD"
call system("echo -e '!_TAG_FILE_SORTED\t2\t/2=foldcase/' > filenametags")
call system("find `pwd` -not -regex '.*\.\(png\|gif\)' -type f -printf '%f\t%p\t1\n' | sort -f >> filenametags")
endfunction


map <F12> :call Do_CsTag()<CR>
function Do_CsTag()
    let dir = getcwd()


    if filereadable("tags")
let tagsdeleted=delete("./"."tags")
        if(tagsdeleted!=0)
            echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
            return
        endif
    endif


    if has("cscope")
        silent! execute "cs kill -1"
    endif
    if filereadable("cscope.files")
let csfilesdeleted=delete("./"."cscope.in.out")
let csfilesdeleted=delete("./"."cscope.po.out")
let csfilesdeleted=delete("./"."cscope.files")

if(csfilesdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
return
endif
    endif
    if filereadable("cscope.out")
let csoutdeleted=delete("./"."cscope.out")
        
if(csoutdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
            return
        endif
    endif
if filereadable("filenametags")
let csoutdeleted=delete("./"."filenametags")
        
if(csoutdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the filenametags" | echohl None
            return
        endif
endif


if(executable('cscope') && has("cscope") && executable('ctags'))
silent! execute"!find `pwd` -name '*.h' -o -name '*.c++' -o -name '*.cc' -o -name '*.cp' -o -name '*.cpp' -o -name '*.cxx' -o -name '*.h++' -o -name '*.hh' -o -name '*.hp' -o -name '*.hpp' -o -name '*.hxx' -o -name '*.C' -o -name '*.H' -o -name '*.ipp' -o -name '*.c' -o -name '*.js' -o -name '*.java' -o -name '*.idl' -o -name '*.mak' -o -name '*.mk' -o -name '[Mm]akefile' -o -name 'GNUmakefile' -o -name '*.pl' -o -name '*.pm' -o -name '*.plx' -o -name '*.perl' -o -name '*.cmake' -o -name '*.y' -o -name '*.sh' -o -name 'CMakeList*.txt'> cscope.files"
silent! execute "!cscope -Rbkq -i cscope.files"
silent! execute "!ctags -R --languages=+c,c++,java,javascript,make,perl,yacc,sh --langmap=c:+.x,c++:+.inl,make:+.mk.cmake --c-kinds=+px --c++-kinds=+px --fields=+afmikKlnsStz --extra=+q --exclude=lex.yy.cc --exclude=copy_lex.yy.cc"
        "silent! execute "!cscope -b"
        execute "normal :"


        if filereadable("cscope.out")
            "let csoutdeleted=delete("./"."cscope.in.out")
            "let csoutdeleted=delete("./"."cscope.po.out")
execute "cs add cscope.out"
            let csoutdeleted=delete("./"."cscope.files")
call system("echo -e '!_TAG_FILE_SORTED\t2\t/2=foldcase/' > filenametags")
            call system("find `pwd` -not -regex '.*\.\(png\|gif\)' -type f -printf '%f\t%p\t1\n' | sort -f >> filenametags")
        endif
    endif
endfunction


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""" color""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if &bg == "dark"   " 根據你的背景色風格來設置不一樣的書籤顏色
 highlight SignColor ctermfg=white ctermbg=blue guifg=wheat guibg=peru
else               " 主要就是修改guibg的值來設置書籤的顏色
 highlight SignColor ctermbg=white ctermfg=blue guibg=grey guifg=RoyalBlue3
endif


if $TERM =~ '^xterm' || $TERM =~ '^screen' || $TERM=~ '256color$'
    set t_Co=256
    set background=dark
colorscheme darkblue
elseif has('gui_running')
    set background=light
    colorscheme solarized
elseif $TERM =~ 'cons256'
    colorscheme default
endif


"colorscheme lucius
"colorscheme evening
"colorscheme eclipse
"colorscheme darkblue
colorscheme maroloccio
"colorscheme peaksea
"colorscheme vanzan_color
"colorscheme zenburn
"colorscheme solarized
"colorscheme molokai
"colorscheme desert
"colorscheme earth
"colorscheme xterm16
"colorscheme xemacs
"colorscheme ashen
"colorscheme autumnleat
"colorscheme zellner
"colorscheme calmar256-light
"colorscheme calmar256-dark
"colorscheme blacklight
"colorscheme putty
"colorscheme shine
"colorscheme morning

 

===============================================華麗的分割線

vim plugin 下載配置腳本: .vimrc.bundles (保存文件名放到你$HOME目錄)

 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" bundle 插件管理和配置項""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""包依賴"""""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"package dependence:  ctags
"python dependence:   pep8, pyflake


"非兼容vi模式。去掉討厭的有關vi一致性模式,避免之前版本的一些bug和侷限
set nocompatible
" configure Vundle
filetype off " required! turn off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""插件管理"""""""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


" 使用Vundle來管理插件
" vim plugin bundle control, command model
"     :BundleInstall     install 安裝配置的插件
"     :BundleInstall!    update  更新
"     :BundleClean       remove plugin not in list 刪除本地無用插件
Bundle 'gmarik/vundle'


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""基礎""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 多語言語法檢查
Bundle 'scrooloose/syntastic'
let g:syntastic_error_symbol = '✗'      "set error or warning signs
let g:syntastic_warning_symbol = '⚠'
let g:syntastic_check_on_open=1
let g:syntastic_enable_highlighting = 0
let g:syntastic_python_checkers=['pyflakes'] " 使用pyflakes,速度比pylint快
let g:syntastic_javascript_checkers = ['jsl', 'jshint']
let g:syntastic_html_checkers=['tidy', 'jshint']
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++'
let g:syntastic_enable_balloons = 1 "whether to show balloons
highlight SyntasticErrorSign guifg=white guibg=black


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""自動補全"""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 代碼自動補全
"迄今爲止用到的最好的自動VIM自動補全插件
"重啓 :YcmRestartServer
Bundle 'Valloric/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>']
let g:ycm_complete_in_comments = 1  "在註釋輸入中也能補全
let g:ycm_complete_in_strings = 1   "在字符串輸入中也能補全
let g:ycm_use_ultisnips_completer = 1 "提示UltiSnips
let g:ycm_cache_omnifunc = 0        " 禁止緩存匹配項,每次都從新生成匹配項
let g:ycm_collect_identifiers_from_comments_and_strings = 0   "註釋和字符串中的文字也會被收入補全
let g:ycm_seed_identifiers_with_syntax = 0   "語言關鍵字補全, 不過python關鍵字都很短,因此,須要的本身打開
"let g:ycm_collect_identifiers_from_tags_files = 1 "會致使一直更新標籤,python2 佔用內存80%以上
" 引入,能夠補全系統,以及python的第三方包 針對新老版本YCM作了兼容
" old version
"if !empty(glob("~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"))
"    let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"
"endif
" new version
if !empty(glob("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"))
    let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"
endif


" 直接觸發自動補全
"let g:ycm_key_invoke_completion = '<C-Space>'
" 跳轉到定義處, 分屏打開
let g:ycm_goto_buffer_command = 'horizontal-split'
" nnoremap <leader>jd :YcmCompleter GoToDefinition<CR>
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <leader>gd :YcmCompleter GoToDeclaration<CR>


" 黑名單,不啓用
let g:ycm_filetype_blacklist = {
      \ 'tagbar' : 1,
      \ 'gitcommit' : 1,
      \}




" 代碼片斷快速插入 (snippets中,是代碼片斷資源,須要學習)
Bundle 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Bundle 'honza/vim-snippets'


let g:UltiSnipsExpandTrigger       = "<tab>"
let g:UltiSnipsJumpForwardTrigger  = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
let g:UltiSnipsSnippetDirectories  = ['UltiSnips']
let g:UltiSnipsSnippetsDir = '~/.vim/UltiSnips'
" 定義存放代碼片斷的文件夾 .vim/UltiSnips下,使用自定義和默認的,將會的到全局,有衝突的會提示
" 進入對應filetype的snippets進行編輯
map <leader>us :UltiSnipsEdit<CR>


" ctrl+j/k 進行選擇
func! g:JInYCM()
    if pumvisible()
        return "\<C-n>"
    else
        return "\<c-j>"
    endif
endfunction


func! g:KInYCM()
    if pumvisible()
        return "\<C-p>"
    else
        return "\<c-k>"
    endif
endfunction
inoremap <c-j> <c-r>=g:JInYCM()<cr>
au BufEnter,BufRead * exec "inoremap <silent> " . g:UltiSnipsJumpBackwordTrigger . " <C-R>=g:KInYCM()<cr>"
let g:UltiSnipsJumpBackwordTrigger = "<c-k>"




" 自動補全單引號,雙引號等
Bundle 'Raimondi/delimitMate'
"" for python docstring ",優化輸入
au FileType python let b:delimitMate_nesting_quotes = ['"']




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


"################### 快速編碼 ###################


" 快速註釋
Bundle 'scrooloose/nerdcommenter'
let g:NERDSpaceDelims=1




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


" 快速去行尾空格 [, + <Space>]
Bundle 'bronson/vim-trailing-whitespace'
map <leader><space> :FixWhitespace<cr>


" 快速賦值語句對齊
Bundle 'junegunn/vim-easy-align'
vmap <Leader>a <Plug>(EasyAlign)
nmap <Leader>a <Plug>(EasyAlign)
if !exists('g:easy_align_delimiters')
  let g:easy_align_delimiters = {}
endif
let g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignore_groups': ['String'] }


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""快速移動 """"""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"更高效的移動 [,, + w/fx]
Bundle 'Lokaltog/vim-easymotion'
let g:EasyMotion_smartcase = 1
" let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
map <Leader><leader>h <Plug>(easymotion-linebackward)
map <Leader><Leader>j <Plug>(easymotion-j)
map <Leader><Leader>k <Plug>(easymotion-k)
map <Leader><leader>l <Plug>(easymotion-lineforward)


Bundle 'vim-scripts/matchit.zip'


" 顯示marks - 方便本身進行標記和跳轉
" m[a-zA-Z] add mark
" '[a-zA-Z] go to mark
" m<Space>  del all marks
Bundle "kshenoy/vim-signature"


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""文本對象""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


" 支持自定義文本對象
Bundle 'kana/vim-textobj-user.git'
" 增長行文本對象: l   dal yal cil
Bundle 'kana/vim-textobj-line'
" 增長文件文本對象: e   dae yae cie
Bundle 'kana/vim-textobj-entire.git'
" 增長縮進文本對象: i   dai yai cii - 相同縮進屬於同一塊
Bundle 'kana/vim-textobj-indent.git'


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""快速選中""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 選中區塊
Bundle 'terryma/vim-expand-region'
map + <Plug>(expand_region_expand)
map _ <Plug>(expand_region_shrink)


" 多光標選中編輯
Bundle 'terryma/vim-multiple-cursors'
let g:multi_cursor_use_default_mapping=0
" Default mapping
let g:multi_cursor_next_key='<C-m>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""功能相關""""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Bundle 'vim-scripts/bufexplorer.zip'
"Bundle 'vim-scripts/winmanager'
"Bundle 'xolox/vim-misc'
"Bundle 'xolox/vim-shell'
Bundle 'vim-scripts/a.vim'
Bundle 'vim-scripts/vcscommand.vim'


" 文件搜索
" change to https://github.com/ctrlpvim/ctrlp.vim
Bundle 'ctrlpvim/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_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


" ctrlp插件1 - 不用ctag進行函數快速跳轉
Bundle 'tacahiroy/ctrlp-funky'
nnoremap <Leader>fu :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']


" git.  git操做仍是習慣命令行,vim裏面處理簡單diff編輯操做
Bundle 'tpope/vim-fugitive'
":Gdiff  :Gstatus :Gvsplit
nnoremap <leader>ge :Gdiff<CR>
" not ready to open
" <leader>gb maps to :Gblame<CR>
" <leader>gs maps to :Gstatus<CR>
" <leader>gd maps to :Gdiff<CR>  和現有衝突
" <leader>gl maps to :Glog<CR>
" <leader>gc maps to :Gcommit<CR>
" <leader>gp maps to :Git push<CR>


" 同git diff,實時展現文件中修改的行
" 只是不喜歡除了行號多一列, 默認關閉,gs時打開
Bundle 'airblade/vim-gitgutter'
let g:gitgutter_map_keys = 0
let g:gitgutter_enabled = 0
let g:gitgutter_highlight_lines = 1
nnoremap <leader>gs :GitGutterToggle<CR>


" edit history, 能夠查看回到某個歷史狀態
Bundle 'sjl/gundo.vim'
nnoremap <leader>h :GundoToggle<CR>


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""顯示加強"""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"狀態欄加強展現
" 新的airline配置
Bundle 'bling/vim-airline'
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 = '⎇'




"括號顯示加強
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'
"let g:molokai_original = 1


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""快速導航"""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"目錄導航
Bundle 'scrooloose/nerdtree'
map <leader>n :NERDTreeToggle<CR>
let NERDTreeHighlightCursorline=1
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ]
"let NERDTreeDirArrows=0
"let g:netrw_home='~/bak'
"close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | end
" s/v 分屏打開文件
let g:NERDTreeMapOpenSplit = 's'
let g:NERDTreeMapOpenVSplit = 'v'




Bundle 'jistr/vim-nerdtree-tabs'
map <Leader>n <plug>NERDTreeTabsToggle<CR>
" 關閉同步
let g:nerdtree_tabs_synchronize_view=0
let g:nerdtree_tabs_synchronize_focus=0
" 自動開啓nerdtree
"let g:nerdtree_tabs_open_on_console_startup=1




" Vim Workspace Controller
Bundle "szw/vim-ctrlspace"
let g:airline_exclude_preview = 1
hi CtrlSpaceSelected guifg=#586e75 guibg=#eee8d5 guisp=#839496 gui=reverse,bold ctermfg=10 ctermbg=7 cterm=reverse,bold
hi CtrlSpaceNormal   guifg=#839496 guibg=#021B25 guisp=#839496 gui=NONE ctermfg=12 ctermbg=0 cterm=NONE
hi CtrlSpaceSearch   guifg=#cb4b16 guibg=NONE gui=bold ctermfg=9 ctermbg=NONE term=bold cterm=bold
hi CtrlSpaceStatus   guifg=#839496 guibg=#002b36 gui=reverse term=reverse cterm=reverse ctermfg=12 ctermbg=8


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>
noremap <leader>bn :MBEbn<CR>
noremap <leader>bp :MBEbp<CR>
noremap <leader>bd :MBEbd<CR>


"標籤導航
Bundle 'majutsushi/tagbar'
"nmap <F9> :TagbarToggle<CR>
let g:tagbar_autofocus = 1
let g:tagbar_left = 1
let g:tagbar_expand = 1
let g:tagbar_compact = 1
let g:tagbar_singleclick = 1
let g:tagbar_autoshowtag = 1
let g:tagbar_ctags_bin = 'ctags'
let g:tagbar_width = 30


" for ruby
let g:tagbar_type_ruby = {
    \ 'kinds' : [
        \ 'm:modules',
        \ 'c:classes',
        \ 'd:describes',
        \ 'C:contexts',
        \ 'f:methods',
        \ 'F:singleton methods'
    \ ]
\ }


" go語言的tagbar配置
" 1.install gotags 'go get -u github.com/jstemmer/gotags'
" 2.make sure `gotags` in you shell PATH, you can call check it with `which gotags`
" for gotags. work with tagbar
let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ }


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""語言相關""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"###### Python #########
" python fly check, 彌補syntastic只能打開和保存才檢查語法的不足
Bundle 'kevinw/pyflakes-vim'
let g:pyflakes_use_quickfix = 0


" for python.vim syntax highlight
Bundle 'hdima/python-syntax'
let python_highlight_all = 1


"###### Golang #########
" 1.install golang and install gocode 'go get github.com/nsf/gocode'
" 2.make sure gocode in your path: `which gocode` (add $GOPATH/bin to you $PATH)
Bundle 'Blackrush/vim-gocode'
"Bundle 'fatih/vim-go.git'


"###### Ruby #########
" Bundle 'vim-ruby/vim-ruby'
" Bundle 'nelstrom/vim-textobj-rubyblock'


" 有bug, 和當前有衝突, 還沒有解決, 不要打開
" Bundle 'tpope/vim-endwise'




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


"###### HTML/JS/JQUERY/CSS #########


" for javascript  注意: syntax這個插件要放前面
Bundle 'jelera/vim-javascript-syntax'
Bundle "pangloss/vim-javascript"
let g:html_indent_inctags = "html,body,head,tbody"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"




" for javascript 自動補全,配合YCM,須要安裝nodejs&npm  see
" https://github.com/marijnh/tern_for_vim
" Bundle 'marijnh/tern_for_vim'


"for jquery
Bundle 'nono/jquery.vim'


"###### emmet HTML complete #########
"Bundle "mattn/emmet-vim"


"###### vim.less : less 自動更新##########
" Bundle 'groenewege/vim-less'
" autocmd BufWritePost *.less :!lessc % > %:p:r.css


"###### Jinja2 #########
Bundle 'Glench/Vim-Jinja2-Syntax'


"for css color
"not work in iterm2 which termianl selection is not xterm-256
" Bundle 'ap/vim-css-color'


" 這個有坑, see issue https://github.com/wklken/k-vim/issues/49
"Bundle 'gorodinskiy/vim-coloresque'


"###### nginx #########
" Bundle 'evanmiller/nginx-vim-syntax'


" 待審查
" Bundle "thinca/vim-quickrun"
" nnoremap <F10> :QuickRun<cr>


Bundle 'vim-scripts/gtags.vim'


" All of your Plugins must be added before the following line
"call vundle#end()            " required
"filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" bundle 插件管理和配置項""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""包依賴"""""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"package dependence:  ctags
"python dependence:   pep8, pyflake


"非兼容vi模式。去掉討厭的有關vi一致性模式,避免之前版本的一些bug和侷限
set nocompatible
" configure Vundle
filetype off " required! turn off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""插件管理"""""""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


" 使用Vundle來管理插件
" vim plugin bundle control, command model
"     :BundleInstall     install 安裝配置的插件
"     :BundleInstall!    update  更新
"     :BundleClean       remove plugin not in list 刪除本地無用插件
Bundle 'gmarik/vundle'


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""基礎""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 多語言語法檢查
Bundle 'scrooloose/syntastic'
let g:syntastic_error_symbol = '✗'      "set error or warning signs
let g:syntastic_warning_symbol = '⚠'
let g:syntastic_check_on_open=1
let g:syntastic_enable_highlighting = 0
let g:syntastic_python_checkers=['pyflakes'] " 使用pyflakes,速度比pylint快
let g:syntastic_javascript_checkers = ['jsl', 'jshint']
let g:syntastic_html_checkers=['tidy', 'jshint']
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++'
let g:syntastic_enable_balloons = 1 "whether to show balloons
highlight SyntasticErrorSign guifg=white guibg=black


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""自動補全"""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 代碼自動補全
"迄今爲止用到的最好的自動VIM自動補全插件
"重啓 :YcmRestartServer
Bundle 'Valloric/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>']
let g:ycm_complete_in_comments = 1  "在註釋輸入中也能補全
let g:ycm_complete_in_strings = 1   "在字符串輸入中也能補全
let g:ycm_use_ultisnips_completer = 1 "提示UltiSnips
let g:ycm_cache_omnifunc = 0        " 禁止緩存匹配項,每次都從新生成匹配項
let g:ycm_collect_identifiers_from_comments_and_strings = 0   "註釋和字符串中的文字也會被收入補全
let g:ycm_seed_identifiers_with_syntax = 0   "語言關鍵字補全, 不過python關鍵字都很短,因此,須要的本身打開
"let g:ycm_collect_identifiers_from_tags_files = 1 "會致使一直更新標籤,python2 佔用內存80%以上
" 引入,能夠補全系統,以及python的第三方包 針對新老版本YCM作了兼容
" old version
"if !empty(glob("~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"))
"    let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py"
"endif
" new version
if !empty(glob("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"))
    let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"
endif


" 直接觸發自動補全
"let g:ycm_key_invoke_completion = '<C-Space>'
" 跳轉到定義處, 分屏打開
let g:ycm_goto_buffer_command = 'horizontal-split'
" nnoremap <leader>jd :YcmCompleter GoToDefinition<CR>
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <leader>gd :YcmCompleter GoToDeclaration<CR>


" 黑名單,不啓用
let g:ycm_filetype_blacklist = {
      \ 'tagbar' : 1,
      \ 'gitcommit' : 1,
      \}




" 代碼片斷快速插入 (snippets中,是代碼片斷資源,須要學習)
Bundle 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Bundle 'honza/vim-snippets'


let g:UltiSnipsExpandTrigger       = "<tab>"
let g:UltiSnipsJumpForwardTrigger  = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
let g:UltiSnipsSnippetDirectories  = ['UltiSnips']
let g:UltiSnipsSnippetsDir = '~/.vim/UltiSnips'
" 定義存放代碼片斷的文件夾 .vim/UltiSnips下,使用自定義和默認的,將會的到全局,有衝突的會提示
" 進入對應filetype的snippets進行編輯
map <leader>us :UltiSnipsEdit<CR>


" ctrl+j/k 進行選擇
func! g:JInYCM()
    if pumvisible()
        return "\<C-n>"
    else
        return "\<c-j>"
    endif
endfunction


func! g:KInYCM()
    if pumvisible()
        return "\<C-p>"
    else
        return "\<c-k>"
    endif
endfunction
inoremap <c-j> <c-r>=g:JInYCM()<cr>
au BufEnter,BufRead * exec "inoremap <silent> " . g:UltiSnipsJumpBackwordTrigger . " <C-R>=g:KInYCM()<cr>"
let g:UltiSnipsJumpBackwordTrigger = "<c-k>"




" 自動補全單引號,雙引號等
Bundle 'Raimondi/delimitMate'
"" for python docstring ",優化輸入
au FileType python let b:delimitMate_nesting_quotes = ['"']




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


"################### 快速編碼 ###################


" 快速註釋
Bundle 'scrooloose/nerdcommenter'
let g:NERDSpaceDelims=1




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


" 快速去行尾空格 [, + <Space>]
Bundle 'bronson/vim-trailing-whitespace'
map <leader><space> :FixWhitespace<cr>


" 快速賦值語句對齊
Bundle 'junegunn/vim-easy-align'
vmap <Leader>a <Plug>(EasyAlign)
nmap <Leader>a <Plug>(EasyAlign)
if !exists('g:easy_align_delimiters')
  let g:easy_align_delimiters = {}
endif
let g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignore_groups': ['String'] }


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""快速移動 """"""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"更高效的移動 [,, + w/fx]
Bundle 'Lokaltog/vim-easymotion'
let g:EasyMotion_smartcase = 1
" let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
map <Leader><leader>h <Plug>(easymotion-linebackward)
map <Leader><Leader>j <Plug>(easymotion-j)
map <Leader><Leader>k <Plug>(easymotion-k)
map <Leader><leader>l <Plug>(easymotion-lineforward)


Bundle 'vim-scripts/matchit.zip'


" 顯示marks - 方便本身進行標記和跳轉
" m[a-zA-Z] add mark
" '[a-zA-Z] go to mark
" m<Space>  del all marks
Bundle "kshenoy/vim-signature"


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""文本對象""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


" 支持自定義文本對象
Bundle 'kana/vim-textobj-user.git'
" 增長行文本對象: l   dal yal cil
Bundle 'kana/vim-textobj-line'
" 增長文件文本對象: e   dae yae cie
Bundle 'kana/vim-textobj-entire.git'
" 增長縮進文本對象: i   dai yai cii - 相同縮進屬於同一塊
Bundle 'kana/vim-textobj-indent.git'


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""快速選中""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 選中區塊
Bundle 'terryma/vim-expand-region'
map + <Plug>(expand_region_expand)
map _ <Plug>(expand_region_shrink)


" 多光標選中編輯
Bundle 'terryma/vim-multiple-cursors'
let g:multi_cursor_use_default_mapping=0
" Default mapping
let g:multi_cursor_next_key='<C-m>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""功能相關""""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Bundle 'vim-scripts/bufexplorer.zip'
"Bundle 'vim-scripts/winmanager'
"Bundle 'xolox/vim-misc'
"Bundle 'xolox/vim-shell'
Bundle 'vim-scripts/a.vim'
Bundle 'vim-scripts/vcscommand.vim'


" 文件搜索
" change to https://github.com/ctrlpvim/ctrlp.vim
Bundle 'ctrlpvim/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_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


" ctrlp插件1 - 不用ctag進行函數快速跳轉
Bundle 'tacahiroy/ctrlp-funky'
nnoremap <Leader>fu :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']


" git.  git操做仍是習慣命令行,vim裏面處理簡單diff編輯操做
Bundle 'tpope/vim-fugitive'
":Gdiff  :Gstatus :Gvsplit
nnoremap <leader>ge :Gdiff<CR>
" not ready to open
" <leader>gb maps to :Gblame<CR>
" <leader>gs maps to :Gstatus<CR>
" <leader>gd maps to :Gdiff<CR>  和現有衝突
" <leader>gl maps to :Glog<CR>
" <leader>gc maps to :Gcommit<CR>
" <leader>gp maps to :Git push<CR>


" 同git diff,實時展現文件中修改的行
" 只是不喜歡除了行號多一列, 默認關閉,gs時打開
Bundle 'airblade/vim-gitgutter'
let g:gitgutter_map_keys = 0
let g:gitgutter_enabled = 0
let g:gitgutter_highlight_lines = 1
nnoremap <leader>gs :GitGutterToggle<CR>


" edit history, 能夠查看回到某個歷史狀態
Bundle 'sjl/gundo.vim'
nnoremap <leader>h :GundoToggle<CR>


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""顯示加強"""""""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"狀態欄加強展現
" 新的airline配置
Bundle 'bling/vim-airline'
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 = '⎇'




"括號顯示加強
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'
"let g:molokai_original = 1


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""快速導航"""""""""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"目錄導航
Bundle 'scrooloose/nerdtree'
map <leader>n :NERDTreeToggle<CR>
let NERDTreeHighlightCursorline=1
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ]
"let NERDTreeDirArrows=0
"let g:netrw_home='~/bak'
"close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | end
" s/v 分屏打開文件
let g:NERDTreeMapOpenSplit = 's'
let g:NERDTreeMapOpenVSplit = 'v'




Bundle 'jistr/vim-nerdtree-tabs'
map <Leader>n <plug>NERDTreeTabsToggle<CR>
" 關閉同步
let g:nerdtree_tabs_synchronize_view=0
let g:nerdtree_tabs_synchronize_focus=0
" 自動開啓nerdtree
"let g:nerdtree_tabs_open_on_console_startup=1




" Vim Workspace Controller
Bundle "szw/vim-ctrlspace"
let g:airline_exclude_preview = 1
hi CtrlSpaceSelected guifg=#586e75 guibg=#eee8d5 guisp=#839496 gui=reverse,bold ctermfg=10 ctermbg=7 cterm=reverse,bold
hi CtrlSpaceNormal   guifg=#839496 guibg=#021B25 guisp=#839496 gui=NONE ctermfg=12 ctermbg=0 cterm=NONE
hi CtrlSpaceSearch   guifg=#cb4b16 guibg=NONE gui=bold ctermfg=9 ctermbg=NONE term=bold cterm=bold
hi CtrlSpaceStatus   guifg=#839496 guibg=#002b36 gui=reverse term=reverse cterm=reverse ctermfg=12 ctermbg=8


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>
noremap <leader>bn :MBEbn<CR>
noremap <leader>bp :MBEbp<CR>
noremap <leader>bd :MBEbd<CR>


"標籤導航
Bundle 'majutsushi/tagbar'
"nmap <F9> :TagbarToggle<CR>
let g:tagbar_autofocus = 1
let g:tagbar_left = 1
let g:tagbar_expand = 1
let g:tagbar_compact = 1
let g:tagbar_singleclick = 1
let g:tagbar_autoshowtag = 1
let g:tagbar_ctags_bin = 'ctags'
let g:tagbar_width = 30


" for ruby
let g:tagbar_type_ruby = {
    \ 'kinds' : [
        \ 'm:modules',
        \ 'c:classes',
        \ 'd:describes',
        \ 'C:contexts',
        \ 'f:methods',
        \ 'F:singleton methods'
    \ ]
\ }


" go語言的tagbar配置
" 1.install gotags 'go get -u github.com/jstemmer/gotags'
" 2.make sure `gotags` in you shell PATH, you can call check it with `which gotags`
" for gotags. work with tagbar
let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ }


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""語言相關""""""""""""""""""""""""""""""""""""""" 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"###### Python #########
" python fly check, 彌補syntastic只能打開和保存才檢查語法的不足
Bundle 'kevinw/pyflakes-vim'
let g:pyflakes_use_quickfix = 0


" for python.vim syntax highlight
Bundle 'hdima/python-syntax'
let python_highlight_all = 1


"###### Golang #########
" 1.install golang and install gocode 'go get github.com/nsf/gocode'
" 2.make sure gocode in your path: `which gocode` (add $GOPATH/bin to you $PATH)
Bundle 'Blackrush/vim-gocode'
"Bundle 'fatih/vim-go.git'


"###### Ruby #########
" Bundle 'vim-ruby/vim-ruby'
" Bundle 'nelstrom/vim-textobj-rubyblock'


" 有bug, 和當前有衝突, 還沒有解決, 不要打開
" Bundle 'tpope/vim-endwise'




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


"###### HTML/JS/JQUERY/CSS #########


" for javascript  注意: syntax這個插件要放前面
Bundle 'jelera/vim-javascript-syntax'
Bundle "pangloss/vim-javascript"
let g:html_indent_inctags = "html,body,head,tbody"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"




" for javascript 自動補全,配合YCM,須要安裝nodejs&npm  see
" https://github.com/marijnh/tern_for_vim
" Bundle 'marijnh/tern_for_vim'


"for jquery
Bundle 'nono/jquery.vim'


"###### emmet HTML complete #########
"Bundle "mattn/emmet-vim"


"###### vim.less : less 自動更新##########
" Bundle 'groenewege/vim-less'
" autocmd BufWritePost *.less :!lessc % > %:p:r.css


"###### Jinja2 #########
Bundle 'Glench/Vim-Jinja2-Syntax'


"for css color
"not work in iterm2 which termianl selection is not xterm-256
" Bundle 'ap/vim-css-color'


" 這個有坑, see issue https://github.com/wklken/k-vim/issues/49
"Bundle 'gorodinskiy/vim-coloresque'


"###### nginx #########
" Bundle 'evanmiller/nginx-vim-syntax'


" 待審查
" Bundle "thinca/vim-quickrun"
" nnoremap <F10> :QuickRun<cr>


Bundle 'vim-scripts/gtags.vim'


" All of your Plugins must be added before the following line
"call vundle#end()            " required
"filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

===============================================華麗的分割線

 

 
 

第一時間得到博客更新提醒,以及更多技術信息分享,歡迎關注我的微信公衆平臺:程序員互動聯盟

 

1.第一時間得到業內十多個領域的原創技術文章

2.對於文章內有疑問能夠當即提出問題,第一時間獲得回覆,以及耐心的解答。

3.能夠和原創文章做者成爲很好的朋友,拓展本身的人脈資源。

掃一掃下方二維碼或搜索微信號coder_online便可關注,咱們能夠在線交流。

相關文章
相關標籤/搜索