1 " Bundle ------------------------------------------------------------------ {{{
2 " Sun Sep 21 00:46:43 CST 2014
3 " refer https://github.com/connermcd/dotfiles.git
4 " and https://bitbucket.org/sjl/dotfiles
8 set rtp+=~/.vim/bundle/Vundle.vim
11 Plugin 'gmarik/Vundle.vim'
12 Bundle 'vim-scripts/FuzzyFinder'
13 Bundle 'vim-scripts/L9'
14 Bundle 'Valloric/YouCompleteMe'
15 Bundle 'octol/vim-cpp-enhanced-highlight'
16 Bundle 'bling/vim-airline'
17 Bundle 'payneseu/nerdtree'
18 Bundle 'Townk/vim-autoclose'
19 Bundle 'majutsushi/tagbar'
20 Bundle 'vim-scripts/tcd.vim'
21 Bundle 'vim-scripts/cmdline-completion'
22 Bundle 'vim-scripts/vcscommand.vim'
23 Bundle 'Lokaltog/vim-easymotion'
24 Bundle 'vim-scripts/YankRing.vim'
25 Bundle 'vim-scripts/gtags.vim'
26 Bundle 'kshenoy/vim-signature'
27 Bundle 'nathanaelkane/vim-indent-guides'
29 Bundle 'payneseu/mark-2.8.4'
30 "Bundle 'derekwyatt/vim-fswitch'
31 Bundle 'sjl/gundo.vim'
32 Bundle 'tpope/vim-markdown'
33 "Bundle 'vim-scripts/BreakPts'
34 "Bundle 'vim-scripts/genutils'
35 "Bundle 'vim-scripts/Marks-Browser'
36 Bundle 'MattesGroeger/vim-bookmarks'
39 filetype plugin indent on
42 " Basic options ----------------------------------------------------------- {{{
57 set diffopt=filler,vertical
60 set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮
68 set completeopt=longest,menuone
70 "set wildmode=list:longest
72 set wildignore=*.o,*.obj,*~,*.swp,*.DS_Store,*.git,*.svn,*.hg
81 set macmeta "" Macvim only
84 set guifont=Sauce\ Code\ Powerline\ Light:h11
85 highlight Cursor guifg=white guibg=green
86 set guicursor=a:blinkon0
93 " http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTinkbdoZ8eNR1X2UobLTeww1jFrvfJxTMfKSq-L%2B%40mail.gmail.com&forum_name=tmux-users
94 "https://gist.github.com/andyfowler/1195581
96 let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
97 let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
99 let &t_SI = "\<Esc>]50;CursorShape=1\x7"
100 let &t_EI = "\<Esc>]50;CursorShape=0\x7"
106 " Mappings ---------------------------------------------------------------- {{{
109 " Normal mode ------------------------------------------------------------- {{{
116 nmap <Leader>w :w<CR>
117 nmap <Leader>q :q<CR>
118 nmap <Leader>e :e<Space>
119 nmap <Leader>W :w !sudo tee %<CR>
120 nmap <Leader>h :vertical help<Space>
121 nmap <Leader>t :tabedit<Space>
122 "nmap <Leader>x :x<CR>
129 nnoremap <Leader>v <C-W>v
130 nnoremap <Leader>s <C-W>s
138 nnoremap <C-D> M<C-D>
139 nnoremap <C-U> M<C-U>
141 nnoremap <SPACE> <C-F>
142 nnoremap <S-SPACE> <C-B>
146 "nmap <A-TAB> :bn<CR>
147 " map <A-TAB> Alt+TAB
148 "noremap <A-S-TAB> "input C-V then input key sequence to
149 "http://vim.wikia.com/wiki/Make_Shift-Tab_work
150 nnoremap <ESC><TAB> :bn<CR>
151 nnoremap
\e\19 :bp<CR>
152 "nmap <A-S-TAB> :bp<CR>
153 "nmap <A-SPACE> :b#<CR>
154 "nmap <Leader>d :bd<CR>
155 "" keymappig for register operations
156 nnoremap <Leader>r :registers<CR>
157 "noremap <Leader>x :<C-p>
163 nmap <A-=> :resize<CR>:vertical resize<CR>
164 nmap
\e= :resize<CR>:vertical resize<CR>
174 noremap <Leader>z zmzvzz
175 nmap \\ :nohlsearch<CR>
177 " Insert mode ------------------------------------------------------------- {{{
179 inoremap <C-U> <C-G>u<C-U>
180 inoremap <C-a> <Home>
183 inoremap <C-b> <S-Left>
184 inoremap <C-f> <S-Right>
185 imap <A-d> <S-Right><C-w>
187 " Command mode ------------------------------------------------------- {{{
189 cnoremap <C-A> <Home>
191 cnoremap <C-B> <Left>
192 cnoremap <C-F> <Right>
196 if has("gui_running")
197 " only for Macvim <D-Left> D is Command key
201 cnoremap <A-b> <S-Left>
202 cnoremap <A-f> <S-Right>
203 cnoremap <A-d> <S-Right><S-Right><S-Left><C-w>
205 cnoremap
\eb <S-Left>
206 cnoremap
\ef <S-Right>
207 cnoremap
\ed <S-Right><S-Right><S-Left><C-w>
209 " delet a word left of cursor
212 " Visual mode ------------------------------------------------------------- {{{
213 "" key mapping for visul mode
220 " Plugins Configuration --------------------------------------------------- {{{
221 " Fuzzy Finder ------------------------------------------------------------ {{{
222 let g:fuf_modesDisable = []
223 let g:fuf_mrufile_maxItem = 400
224 let g:fuf_mrucmd_maxItem = 400
225 let g:fuf_file_exclude = '\v\~$|\.(DS_Store|o|exe|dll|bak|orig|swp|pyc)$|(^|[/\\])\.(hg|git|bzr|svn)($|[/\\])'
226 let g:fuf_buffertag_ctagsPath = '/usr/local/bin/ctags'
227 let g:fuf_enumeratingLimit = 30
228 nnoremap <silent> sj :FufBuffer<CR>
229 nnoremap <silent> sk :FufFileWithCurrentBufferDir<CR>
230 nnoremap <silent> sK :FufFileWithFullCwd<CR>
231 nnoremap <silent> s<C-k> :FufFile<CR>
232 nnoremap <silent> sl :FufCoverageFileChange<CR>
233 nnoremap <silent> sL :FufCoverageFileChange<CR>
234 nnoremap <silent> s<C-l> :FufCoverageFileRegister<CR>
235 nnoremap <silent> sd :FufDirWithCurrentBufferDir<CR>
236 nnoremap <silent> sD :FufDirWithFullCwd<CR>
237 nnoremap <silent> s<C-d> :FufDir<CR>
238 nnoremap <silent> sn :FufMruFile<CR>
239 nnoremap <silent> sN :FufMruFileInCwd<CR>
240 nnoremap <silent> sm :FufMruCmd<CR>
241 nnoremap <silent> su :FufBookmarkFile<CR>
242 nnoremap <silent> s<C-u> :FufBookmarkFileAdd<CR>
243 vnoremap <silent> s<C-u> :FufBookmarkFileAddAsSelectedText<CR>
244 nnoremap <silent> si :FufBookmarkDir<CR>
245 nnoremap <silent> s<C-i> :FufBookmarkDirAdd<CR>
246 nnoremap <silent> sT :FufTag<CR>
247 nnoremap <silent> st :FufTag!<CR>
248 nnoremap <silent> s<C-]> :FufTagWithCursorWord!<CR>
249 nnoremap <silent> s, :FufBufferTag<CR>
250 nnoremap <silent> s< :FufBufferTag!<CR>
251 vnoremap <silent> s, :FufBufferTagWithSelectedText!<CR>
252 vnoremap <silent> s< :FufBufferTagWithSelectedText<CR>
253 nnoremap <silent> s} :FufBufferTagWithCursorWord!<CR>
254 "nnoremap <silent> s. :FufBufferTagAll<CR>
255 "nnoremap <silent> s> :FufBufferTagAll!<CR>
256 "vnoremap <silent> s. :FufBufferTagAllWithSelectedText!<CR>
257 "vnoremap <silent> s> :FufBufferTagAllWithSelectedText<CR>
258 "nnoremap <silent> s] :FufBufferTagAllWithCursorWord!<CR>
259 nnoremap <silent> sG :FufTaggedFile<CR>
260 nnoremap <silent> sg :FufTaggedFile!<CR>
261 nnoremap <silent> so :FufJumpList<CR>
262 nnoremap <silent> sp :FufChangeList<CR>
263 nnoremap <silent> sq :FufQuickfix<CR>
264 nnoremap <silent> sy :FufLine<CR>
265 " nnoremap <silent> sh :FufHelp<CR>
266 nnoremap <silent> se :FufEditDataFile<CR>
267 nnoremap <silent> sr :FufRenewCache<CR>
269 " YouCompleteMe ----------------------------------------------------------- {{{
270 "syntax on, must before the YCM,
272 let g:ycm_collect_identifiers_from_tags_files = 1
273 let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
274 let g:ycm_auto_trigger = 1
275 let g:ycm_seed_identifiers_with_syntax = 1
276 let g:ycm_show_diagnostics_ui = 0
277 let g:ycm_enable_diagnostic_signs = 0
278 set completeopt-=preview " disable preview windows for completion
279 let g:ycm_confirm_extra_conf = 0
280 " delete default mapping for <leader>d
281 let g:ycm_key_detailed_diagnostics = ''
284 " Airline ----------------------------------------------------------------- {{{
285 "if has("gui_running")
287 let g:airline_mode_map = {
301 let g:airline_theme = 'badwolf'
303 "if has("gui_running")
304 let g:airline_powerline_fonts=1
305 let g:airline_left_sep = ''
306 let g:airline_left_alt_sep = ''
307 let g:airline_right_sep = ''
308 let g:airline_right_alt_sep = ''
310 let g:airline#extensions#tabline#show_buffers = 1
311 let g:airline#extensions#tabline#enabled = 1
312 let g:airline#extensions#tabline#left_sep = ''
313 let g:airline#extensions#tabline#left_alt_sep =''
314 let g:airline#extensions#tagbar#enabled = 1
316 " let g:airline_powerline_fonts=1
317 " let g:airline_left_sep = ''
318 "" let g:airline_left_alt_sep = ''
319 " let g:airline_right_sep = ''
320 "" let g:airline_right_alt_sep = ''
322 " let g:airline#extensions#tabline#show_buffers = 0
323 " let g:airline#extensions#tabline#enabled = 1
324 " let g:airline#extensions#tabline#left_sep = ''
325 "" let g:airline#extensions#tabline#left_alt_sep =''
326 " let g:airline#extensions#tagbar#enabled = 1
329 " let g:airline_section_a = 'N'
330 let g:airline_section_b = '%f%m'
331 let g:airline_section_c = ''
332 let g:airline_section_x = '[%-.50{CurDir()}]'
333 let g:airline_section_y = '%y'
334 let g:airline_section_z = '%c, %l/%L %p%%'
335 let g:airline_section_warning = '' " (syntastic, whitespace)
338 set statusline=\ %<%F%m%=[%-.50{CurDir()}]\ %y\ %c,\ %l/%L\ \ %p%%\
340 let curdir = substitute(getcwd(), $HOME, "~", "g")
346 " NerdTree ---------------------------------------------------------------- {{{
347 nmap <Leader>n :NERDTreeToggle<CR>
348 nmap <Leader>N :NERDTreeFind<CR>
350 " AutoClose --------------------------------------------------------------- {{{
351 let g:AutoCloseProtectedRegions = ["Dialog", "ThoughBubble"]
353 " TagBar ------------------------------------------------------------------ {{{
354 noremap <Leader>f :TagbarToggle<CR><C-w>l
355 let Tlist_Ctags_Cmd="/usr/local/bin/ctags"
357 " Tcd --------------------------------------------------------------------- {{{
360 " cmdline-completion ------------------------------------------------------ {{{
361 "http://foocoder.com/blog/mei-ri-vimcha-jian-suo-jin-xian-shi-vim-indent-guides.html/
362 cmap <C-J> <Plug>CmdlineCompletionBackward
363 cmap <C-K> <Plug>CmdlineCompletionForward
365 " VSCCommand -------------------------------------------------------------- {{{
366 "" ============== VCSCommand.vim =====================
367 "let VCSCommandSVKExec='disabled no such executable'
368 let VCSCommandDeleteOnHide=1
369 let VCSCommandDisableMappings=1
370 "let VCSCommandEnableBufferSetup=1
371 "nmap <Leader>sd :VCSVimDiff<CR>
373 autocmd User VCSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr> | setlocal nomodifiable
375 nmap <Leader>dg :diffget<CR>
377 " YankRing ---------------------------------------------------------------- {{{
378 let g:yankring_min_element_length = 2
380 let g:yankring_replace_n_pkey = '<A->>'
381 let g:yankring_replace_n_nkey = '<A-<>'
382 let g:yankring_history_dir = "$HOME/.vim/temp/"
384 " Gtags ------------------------------------------------------------------- {{{
385 if has("gui_running")
386 noremap <A-.> :Gtags<CR>
387 noremap <A-r> :Gtags -r<CR>
388 noremap <A-o> :Gtags -s<CR>
389 noremap <A-g> :Gtags -g<CR>
391 noremap
\e. :Gtags<CR>
392 noremap
\er :Gtags -r<CR>
393 " noremap j :Gtags -s<CR>
394 noremap
\eg :Gtags -g<CR>
397 " Marks ------------------------------------------------------------------- {{{
398 nmap \h <Plug>MarkSet
399 nmap * <Plug>MarkSearchNext
400 nmap # <Plug>MarkSearchPrev
402 " Gundo ------------------------------------------------------------------- {{{
403 " nnoremap <F5> :GundoToggle<CR>
405 " Bookmarks --------------------------------------------------------------- {{{
407 let g:bookmark_save_per_working_dir = 1
408 let g:bookmark_auto_close = 1
409 let g:bookmark_auto_save = 1
410 " unmap the default mapping in plugins
411 nmap <Plug>DisableBookmarkToggle <Plug>BookmarkToggle
412 nmap <Plug>DisableBookmarkAnnotate <Plug>BookmarkAnnotate
413 nmap <Plug>DisableBookmarkShowAll <Plug>BookmarkShowAll
414 nmap <Plug>DisableBookmarkNext <Plug>BookmarkNext
415 nmap <Plug>DisableBookmarkPrev <Plug>BookmarkPrev
416 nmap <Plug>DisableBookmarkClear <Plug>BookmarkClear
417 nmap <Plug>DisableBookmarkClearAll <Plug>BookmarkClearAll
419 nmap mm <Plug>BookmarkToggle
420 " nmap ,i <Plug>BookmarkAnnotate
421 nmap \m <Plug>BookmarkShowAll
422 let g:bookmark_center = 1
423 let g:bookmark_auto_close = 1
424 "let g:bookmark_highlight_lines = 1
425 " nmap ,j <Plug>BookmarkNext
426 " nmap ,k <Plug>BookmarkPrev
427 " nmap ,c <Plug>BookmarkClear
428 " nmap ,x <Plug>BookmarkClearAll
432 " FileType ---------------------------------------------------------------- {{{
433 autocmd BufNewFile,BufRead *.log set filetype=logecc
434 autocmd BufNewFile,BufRead *.log.[0-9] set filetype=logecc
435 autocmd BufNewFile,BufRead *tmux.conf set filetype=tmux
436 autocmd BufNewFile,BufRead SConstruct set filetype=python
437 autocmd BufNewFile,BufRead SConscript* set filetype=python
438 autocmd BufNewFile,BufReadPost *.md set filetype=markdown
439 " http://vim.wikia.com/wiki/Update_the_diff_view_automatically
440 autocmd InsertLeave,BufWritePost,CursorHold * if &diff == 1 | diffupdate | endif
441 " setlocal nomodifiable for svn diff
442 autocmd BufWinEnter *.svn-base setlocal nomodifiable
444 autocmd WinEnter * nnoremap <buffer> gj @=(&diff)?']czz':'gj'<CR> |
445 \ nnoremap <buffer> gk @=(&diff)?'[czz':'gk'<CR>
447 autocmd FileType qf nnoremap <buffer> <silent> q :q<CR> | setlocal nowrap | setlocal nocursorline
448 autocmd FileType help nnoremap <buffer> <silent> q :q<CR> | vertical resize 85;
449 autocmd FileType c,cpp setlocal foldmethod=syntax |
450 \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("\"", "{}") |
451 \ inoremap <buffer> { {<CR>}<ESC>kA<CR>
452 autocmd FileType python setlocal foldmethod=indent
454 autocmd FileType xml setlocal foldmethod=syntax |
455 \ let g:xml_syntax_folding=1
456 autocmd FileType vim setlocal foldmethod=marker |
457 \ setlocal formatoptions-=c formatoptions-=r formatoptions-=o |
458 \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("", "{} \"")
460 autocmd CmdwinEnter * map <buffer> q :q<CR>
463 " Functions --------------------------------------------------------------- {{{
464 " DiffOrig ---------------------------------------------------------------- {{{
465 " refert vimrc_example.vim
466 " Convenient command to see the difference between the current buffer and the
467 " file it was loaded from, thus the changes you made.
468 " Only define it when not defined already.
469 if !exists(":DiffOrig")
470 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
471 \ | wincmd p | diffthis
474 " Fold Quickfix ----------------------------------------------------------- {{{
475 "http://vim.wikia.com/wiki/Show_only_lines_in_quickfix_list_for_current_buffer
476 if ! exists('g:foldmisses_context')
477 let g:foldmisses_context = 0
480 " Add manual fold from line1 to line2, inclusive.
481 function! s:Fold(line1, line2)
483 execute a:line1.','.a:line2.'fold'
487 " Return list of line numbers for current buffer found in quickfix list.
488 function! s:GetHitLineNumbers(list)
491 if d.valid && d.bufnr == bufnr('')
492 call add(result, d.lnum)
498 function! s:FoldMisses(list, context)
499 setlocal foldmethod=manual
501 let extra = a:context == 99999 ? g:foldmisses_context : a:context
503 for lnum in s:GetHitLineNumbers(a:list)
504 " let start = last==0 ? 1 : last+extra
505 let start = last==0 ? 1 : last+1+extra
506 call s:Fold(start, lnum-1-extra)
509 call s:Fold(last+1+extra, line('$'))
510 " call s:Fold(last+extra, line('$'))
513 ":[N]FoldMisses [N] Show only the lines (and surrounding [N] lines
514 ":[N]FoldLMisses [N] of context) in the current buffer that appear
515 " in the quickfix / location list.
516 " Missed, error-free lines are folded away.
517 command! -bar -count=99999 FoldMisses call s:FoldMisses(getqflist(), <count>)
518 command! -bar -count=99999 FoldLMisses call s:FoldMisses(getloclist(0), <count>)
520 " ToggleList -------------------------------------------------------------- {{{
521 "http://vim.wikia.com/wiki/Toggle_to_open_or_close_the_quickfix_window
522 function! GetBufferList()
529 function! ToggleList(bufname, pfx)
530 let buflist = GetBufferList()
531 for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
532 if bufwinnr(bufnum) != -1
537 if a:pfx == 'l' && len(getloclist(0)) == 0
539 echo "Location List is Empty."
549 nmap <silent> \l :call ToggleList("Location List", 'l')<CR>
550 nmap <silent> \q :call ToggleList("Quickfix List", 'c')<CR>
552 " DiffToggle -------------------------------------------------------------- {{{
553 "if !exists(":DiffToggle")
556 function! DiffToggle()
558 diffoff | wincmd h | wincmd o
560 exec ":VCSVimDiff" | wincmd h
563 nnoremap \d :call DiffToggle()<CR>
564 "noremap <Leader>d @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
569 "nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
570 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
571 "noremap <Leader>d @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
573 " https://bitbucket.org/sjl/dotfiles/src/tip/vim/vimrc
574 " Make sure Vim returns to the same line when you reopen a file.
579 \ if line("'\"") > 0 && line("'\"") <= line("$") |
580 \ execute 'normal! g`"zvzz' |
584 iabbrev -... <C-R>=repeat('-', 80 - col(".") - 4 ) . " {{{"
588 " to show the key sequence when pressing some key,
594 " some prefix for mapping
601 nnoremap <C-N> :cn<CR>
602 nnoremap <C-P> :cp<CR>
603 "http://dougblack.io/words/a-good-vimrc.html
605 set nostartofline " don't jump to first character when paging