update
[dotfiles.git] / vim / vimrc
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
5 set nocompatible
6 filetype off
7
8 set rtp+=~/.vim/bundle/Vundle.vim
9 call vundle#begin()
10
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 'vim-airline/vim-airline'
17 Bundle 'vim-airline/vim-airline-themes'
18 Bundle 'payneseu/nerdtree'
19 Bundle 'Townk/vim-autoclose'
20 Bundle 'majutsushi/tagbar'
21 Bundle 'vim-scripts/tcd.vim'
22 Bundle 'vim-scripts/cmdline-completion'
23 Bundle 'vim-scripts/vcscommand.vim'
24 Bundle 'Lokaltog/vim-easymotion'
25 "Bundle 'vim-scripts/YankRing.vim'
26 Bundle 'vim-scripts/gtags.vim'
27 Bundle 'kshenoy/vim-signature'
28 Bundle 'nathanaelkane/vim-indent-guides'
29 Bundle 'rking/ag.vim'
30 Bundle 'payneseu/mark-2.8.4'
31 "Bundle 'derekwyatt/vim-fswitch'
32 Bundle 'sjl/gundo.vim'
33 Bundle 'tpope/vim-markdown'
34 "Bundle 'vim-scripts/BreakPts'
35 "Bundle 'vim-scripts/genutils'
36 "Bundle 'vim-scripts/Marks-Browser'
37 Bundle 'MattesGroeger/vim-bookmarks'
38 "Bundle 'tpope/vim-repeat'
39 "Bundle 'kien/ctrlp.vim'
40 "disable since some conflicting mapping
41 Bundle 'vim-latex/vim-latex'
42 Plugin 'vimperator/vimperator.vim'
43
44 call vundle#end()
45 filetype plugin indent on
46
47 " }}}
48 " Basic options ----------------------------------------------------------- {{{
49 set number
50 set relativenumber
51 set tabstop=4
52 set softtabstop=4
53 set shiftwidth=4
54 set smartindent
55 set smarttab
56 set vb t_vb=
57 set scrolloff=5
58 set sidescroll=10
59 set history=1000
60 set ruler
61 set showcmd
62 set incsearch
63 set hidden
64 set diffopt=filler,vertical
65
66 "set list
67 set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮
68 set ttymouse=xterm2
69 set mouse=a
70 set splitbelow
71 set splitright
72 set nobackup
73 set noswapfile
74 set magic
75 set completeopt=longest,menuone
76 set ttyfast
77 "set wildmode=list:longest
78 set wildmenu
79 set wildignore=*.o,*.obj,*~,*.swp,*.DS_Store,*.git,*.svn,*.hg
80 set lazyredraw
81 set hlsearch
82 set autoindent
83 set confirm
84 set nostartofline   " don't jump to first character when paging
85 set wrap
86 set expandtab
87 "set textwidth, formatoptions for chinese
88 set formatoptions+=m
89 set colorcolumn=+1
90 syntax on
91 " colorscheme {{{
92 set cursorline
93 if has("gui_running")
94         set macmeta  "" Macvim only
95         colorscheme molokai
96         set guioptions+=c
97         set guifont=Source\ Code\ Pro\ Light:h11
98         highlight Cursor guifg=white guibg=green
99         set guicursor=a:blinkon0
100         set guioptions=eac
101 "       set lines=999
102 "       set columns=999
103 else
104         set t_Co=256
105         colorscheme molokai22
106         " http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTinkbdoZ8eNR1X2UobLTeww1jFrvfJxTMfKSq-L%2B%40mail.gmail.com&forum_name=tmux-users
107         "https://gist.github.com/andyfowler/1195581  
108         if exists('$TMUX')
109           let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
110           let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
111         else
112           let &t_SI = "\<Esc>]50;CursorShape=1\x7"
113           let &t_EI = "\<Esc>]50;CursorShape=0\x7"
114         endif"
115 endif
116         
117 " }}}
118 " }}}
119 " Mappings ---------------------------------------------------------------- {{{
120 let mapleader = ";"
121 map Q gq
122 " Normal mode ------------------------------------------------------------- {{{
123 nnoremap Y      y$
124 nnoremap ' `
125 nnoremap ` '
126 nnoremap J      <C-D>
127 nnoremap K      <C-U>
128
129 nmap <Leader>w  :w<CR>
130 nmap <Leader>q  :q<CR>
131 nmap <Leader>e  :e<Space>
132 nmap <Leader>W  :w !sudo tee %<CR>
133 nmap <Leader>h  :vertical help<Space>
134 nmap <Leader>t  :tabedit %<Space>
135 "nmap <Leader>x :x<CR>
136
137 " windows 
138 nmap <C-H>  <C-W>h
139 nmap <C-J>  <C-W>j
140 nmap <C-L>  <C-W>l
141 nmap <C-K>  <C-W>k
142 nnoremap <Leader>v      <C-W>v
143 nnoremap <Leader>s      <C-W>s
144 "nnoremap  so           <C-W>o
145 nmap +  <C-w>3+
146 nmap -  <C-w>3-
147 nmap <  <C-w>3<
148 nmap >  <C-w>3>
149 nmap =  <C-w>=
150
151 nnoremap <C-D>  <C-D>zz
152 nnoremap <C-U>  <C-U>zz
153
154 "nnoremap <SPACE>       <C-F>
155 nnoremap <S-SPACE>      <C-B>
156 nnoremap <BS>   <C-B>
157 nnoremap <A-n>  gt
158 nnoremap <A-p>  gT
159 "nmap <A-TAB>   :bn<CR>
160 " map <A-TAB> Alt+TAB  
161 "noremap <A-S-TAB> "input C-V then input key sequence to
162 "http://vim.wikia.com/wiki/Make_Shift-Tab_work
163 "nnoremap <ESC><TAB> :bn<CR>
164 nnoremap <ESC><TAB> :tabnext<CR>
165 "nnoremap \e\19 :bp<CR>
166 nnoremap \e\19 :tabprevious<CR>
167 "nmap <A-S-TAB> :bp<CR>
168 "nmap <A-SPACE> :b#<CR>
169 "nmap <Leader>d :bd<CR>
170 "" keymappig for register operations
171 ""TODO check if this already mapping
172 "nnoremap <Leader>r     :registers<CR>
173 "noremap <Leader>x      :<C-p>
174 nnoremap <Leader>a :
175
176 nmap <Leader>p  "*p
177 " also works :r !pbpaste<CR>
178
179 nmap <A-=> :resize<CR>:vertical resize<CR>
180 nmap \e= :resize<CR>:vertical resize<CR>
181
182 nnoremap n nzzzv
183 nnoremap N      Nzzzv
184 nnoremap g;     g;zzzv
185 nnoremap g,     g,zzzv
186 nnoremap zR     zRzz
187 nnoremap zr     zrzz
188 nnoremap zn znzz
189
190 nnoremap zj zjzz
191 nnoremap zh zhzz
192
193 noremap <Leader>z       zmzvzz
194 nmap \\ :nohlsearch<CR>
195 " }}}
196 " Insert mode ------------------------------------------------------------- {{{
197 inoremap jj             <Esc>
198 inoremap <C-U> <C-G>u<C-U>
199 inoremap <C-a>  <Home>
200 inoremap <C-e>  <End>
201 inoremap <C-D>  <Del>
202 inoremap <C-b>  <Left>
203 inoremap <C-f>  <Right>
204 inoremap <C-/> <Esc>ui
205 imap <A-d>      <S-Right><C-w>
206 " }}}
207 " Command mode ------------------------------------------------------- {{{
208 cmap jj         <C-c>
209 cnoremap <C-A>  <Home>
210 cnoremap <C-E>  <End>
211 cnoremap <C-B>  <Left>
212 cnoremap <C-F>  <Right>
213 cnoremap <C-D>  <Del>
214
215
216 if has("gui_running")
217 " only for Macvim <D-Left> D is Command key
218         cmap <A-a>      <D-Left>
219         cmap <A-e>      <D-Right>
220
221         cnoremap <A-b>  <S-Left>
222         cnoremap <A-f>  <S-Right>
223         cnoremap <A-d>  <S-Right><S-Right><S-Left><C-w>
224 else
225         cnoremap \eb     <S-Left>
226         cnoremap \ef     <S-Right>
227         cnoremap \ed     <S-Right><S-Right><S-Left><C-w>
228 endif
229 " delet a word left of cursor
230 cmap <S-BS>     <C-w>
231 " }}}
232 " Visual mode ------------------------------------------------------------- {{{
233 "" key mapping for  visul mode
234 vmap <C-k>      {       
235 vmap <C-j>      }       
236 "vmap <Leader>y "*y
237 vmap Y  "*y
238 "
239 "vmap <C-Y>  "qy
240 "vmap <C-P>  "qp
241 vnoremap    Y   "*y
242 vnoremap    <Leader>p  "*p
243 "search for visually selectecd text
244 vnoremap // y/<C-R>"<CR>
245 vnoremap <Leader>a  :
246 " }}}
247 " }}}
248 " Plugins Configuration --------------------------------------------------- {{{
249 " Fuzzy Finder ------------------------------------------------------------ {{{
250 let g:fuf_modesDisable = []
251 let g:fuf_mrufile_maxItem = 400
252 let g:fuf_mrucmd_maxItem = 400
253 let g:fuf_file_exclude = '\v\~$|\.(DS_Store|o|exe|dll|bak|orig|swp|pyc)$|(^|[/\\])\.(hg|git|bzr|svn)($|[/\\])'
254 let g:fuf_buffertag_ctagsPath = '/usr/local/bin/ctags'
255 let g:fuf_enumeratingLimit = 30
256 nnoremap <silent> sj     :FufBuffer<CR>
257 nnoremap <silent> sk     :FufFileWithCurrentBufferDir<CR>
258 nnoremap <silent> sK     :FufFileWithFullCwd<CR>
259 nnoremap <silent> s<C-k> :FufFile<CR>
260 "nnoremap <silent> sl     :FufCoverageFileChange<CR>
261 "nnoremap <silent> sL     :FufCoverageFileChange<CR>
262 "nnoremap <silent> s<C-l> :FufCoverageFileRegister<CR>
263 nnoremap <silent> sd     :FufDirWithCurrentBufferDir<CR>
264 nnoremap <silent> sD     :FufDirWithFullCwd<CR>
265 nnoremap <silent> s<C-d> :FufDir<CR>
266 nnoremap <silent> sn     :FufMruFile<CR>
267 nnoremap <silent> sN     :FufMruFileInCwd<CR>
268 nnoremap <silent> sm     :FufMruCmd<CR>
269 "nnoremap <silent> su     :FufBookmarkFile<CR>
270 nnoremap <silent> s<C-u> :FufBookmarkFileAdd<CR>
271 "vnoremap <silent> s<C-u> :FufBookmarkFileAddAsSelectedText<CR>
272 nnoremap <silent> si     :FufBookmarkDir<CR>
273 nnoremap <silent> s<C-i> :FufBookmarkDirAdd<CR>
274 nnoremap <silent> sT     :FufTag<CR>
275 nnoremap <silent> st     :FufTag!<CR>
276 nnoremap <silent> s<C-]> :FufTagWithCursorWord!<CR>
277 nnoremap <silent> s,     :FufBufferTag<CR>
278 nnoremap <silent> s<     :FufBufferTag!<CR>
279 "vnoremap <silent> s,     :FufBufferTagWithSelectedText!<CR>
280 "vnoremap <silent> s<     :FufBufferTagWithSelectedText<CR>
281 nnoremap <silent> s}     :FufBufferTagWithCursorWord!<CR>
282 nnoremap <silent> sl     :FufBufferTagAll<CR>
283 "nnoremap <silent> s.     :FufBufferTagAll<CR>
284 nnoremap <silent> s>     :FufBufferTagAll!<CR>
285 "vnoremap <silent> s.     :FufBufferTagAllWithSelectedText!<CR>
286 "vnoremap <silent> s>     :FufBufferTagAllWithSelectedText<CR>
287 "nnoremap <silent> s]     :FufBufferTagAllWithCursorWord!<CR>
288 nnoremap <silent> sG     :FufTaggedFile<CR>
289 nnoremap <silent> sg     :FufTaggedFile!<CR>
290 "nnoremap <silent> so     :FufJumpList<CR>
291 "nnoremap <silent> sp     :FufChangeList<CR>
292 "nnoremap <silent> sq     :FufQuickfix<CR>
293 "nnoremap <silent> sy     :FufLine<CR>
294 "  nnoremap <silent> sh     :FufHelp<CR>
295 "nnoremap <silent> se     :FufEditDataFile<CR>
296 nnoremap <silent> sr     :FufRenewCache<CR>
297 " }}}
298 " YouCompleteMe ----------------------------------------------------------- {{{
299 "syntax on, must before the YCM,
300
301 " Load YouCompleteMe only on OSX
302 if !has("osx")
303     let g:loaded_youcompleteme = 1
304 endif
305
306 "let g:ycm_collect_identifiers_from_tags_files = 1
307 let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
308 " this is fix youcompleteme python error
309 "http://www.cnblogs.com/clivelee/p/4266559.html
310 "https://github.com/Valloric/YouCompleteMe/issues/18
311 "let g:ycm_path_to_python_interpreter= '/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
312 let g:ycm_auto_trigger = 1
313 let g:ycm_seed_identifiers_with_syntax = 1
314 let g:ycm_show_diagnostics_ui = 0
315 let g:ycm_enable_diagnostic_signs = 0
316 set completeopt-=preview   " disable preview windows for completion
317 let g:ycm_confirm_extra_conf = 0
318 " delete default mapping for <leader>d
319 let g:ycm_key_detailed_diagnostics = ''
320
321 " }}}
322 " Airline ----------------------------------------------------------------- {{{
323 "if has("gui_running")
324
325   let g:airline_mode_map = {
326       \ '__' : '-',
327       \ 'n'  : 'N',
328       \ 'i'  : 'I',
329       \ 'R'  : 'R',
330       \ 'c'  : 'C',
331       \ 'v'  : 'V',
332       \ 'V'  : 'V',
333       \ '\16' : 'V',
334       \ 's'  : 'S',
335       \ 'S'  : 'S',
336       \ '\13' : 'S',
337       \ }
338
339         let g:airline_theme = 'badwolf'
340
341 "if has("gui_running")
342         let g:airline_powerline_fonts=1
343         let g:airline_left_sep = ''
344         let g:airline_left_alt_sep = ''
345         let g:airline_right_sep = ''
346         let g:airline_right_alt_sep = ''
347
348 "       let g:airline#extensions#tabline#show_buffers = 1
349         let g:airline#extensions#tabline#show_buffers = 0
350         let g:airline#extensions#tabline#enabled = 1
351         let g:airline#extensions#tabline#left_sep = ''
352         let g:airline#extensions#tabline#left_alt_sep =''
353         let g:airline#extensions#tagbar#enabled = 1
354 "else 
355 "       let g:airline_powerline_fonts=1
356 "       let g:airline_left_sep = ''
357 ""      let g:airline_left_alt_sep = ''
358 "       let g:airline_right_sep = ''
359 ""      let g:airline_right_alt_sep = ''
360 "
361 "       let g:airline#extensions#tabline#show_buffers = 0
362 "       let g:airline#extensions#tabline#enabled = 1
363 "       let g:airline#extensions#tabline#left_sep = ''
364 ""      let g:airline#extensions#tabline#left_alt_sep =''
365 "       let g:airline#extensions#tagbar#enabled = 1
366 "endif
367         "
368 "       let g:airline_section_a = 'N'
369         let g:airline_section_b = '%f%m'
370         let g:airline_section_c = ''
371         let g:airline_section_x = '[%-.50{CurDir()}]'
372         let g:airline_section_y = '%y'
373         let g:airline_section_z = '%c, %l/%L %p%%'
374         let g:airline_section_warning = '' " (syntastic, whitespace)
375
376 set laststatus=2
377 set statusline=\ %<%F%m%=[%-.50{CurDir()}]\ %y\ %c,\ %l/%L\ \ %p%%\ 
378 function! CurDir()
379         let curdir = substitute(getcwd(), $HOME, "~", "g")
380         return curdir
381 endfunction
382
383 "endif
384 " }}}
385 " NerdTree ---------------------------------------------------------------- {{{
386 " Fix keymapping conflict
387 nmap <unique> <Leader>, <Plug>MarkClear
388 nmap <Leader>n  :NERDTreeToggle<CR>
389 nmap <Leader>N  :NERDTreeFind<CR>
390 " }}}
391 " AutoClose --------------------------------------------------------------- {{{
392 let g:AutoCloseProtectedRegions = ["Dialog", "ThoughBubble"]
393 " }}}
394 " TagBar ------------------------------------------------------------------ {{{
395 noremap <Leader>f       :TagbarToggle<CR><C-w>l
396 let Tlist_Ctags_Cmd="/usr/local/bin/ctags"
397 " }}}
398 " Tcd --------------------------------------------------------------------- {{{
399 cabbrev cd Tcd
400 " }}}
401 " cmdline-completion ------------------------------------------------------ {{{
402 "http://foocoder.com/blog/mei-ri-vimcha-jian-suo-jin-xian-shi-vim-indent-guides.html/
403 cmap <C-J> <Plug>CmdlineCompletionBackward
404 cmap <C-K> <Plug>CmdlineCompletionForward
405 " }}}
406 " VSCCommand -------------------------------------------------------------- {{{
407 "" ==============  VCSCommand.vim =====================
408 "let VCSCommandSVKExec='disabled no such executable'
409 let VCSCommandDeleteOnHide=1    
410 let VCSCommandDisableMappings=1
411 "let VCSCommandEnableBufferSetup=1
412 "nmap <Leader>sd        :VCSVimDiff<CR>
413 augroup VCSCommand
414         autocmd User VCSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr> | setlocal nomodifiable
415 augroup END
416 nmap <Leader>dg         :diffget<CR>
417 " }}}
418 " YankRing ---------------------------------------------------------------- {{{
419 let g:yankring_min_element_length = 2
420 nmap \r :YRShow<CR>
421 let g:yankring_replace_n_pkey = '<A->>'
422 let g:yankring_replace_n_nkey = '<A-<>'
423 let g:yankring_history_dir = "$HOME/.vim/temp/"
424 " }}}
425 " Gtags ------------------------------------------------------------------- {{{
426 if has("gui_running")
427         noremap <A-.> :Gtags<CR>
428         noremap <A-r> :Gtags -r<CR>
429         noremap <A-o> :Gtags -s<CR>
430         noremap <A-g> :Gtags -g<CR> 
431 else
432         noremap \e. :Gtags<CR>
433         noremap \er :Gtags -r<CR>
434 "       noremap j :Gtags -s<CR>
435         noremap \eg :Gtags -g<CR> 
436 endif
437 " }}}
438 " Marks ------------------------------------------------------------------- {{{
439 nmap  \h <Plug>MarkSet
440 "nmap  * <Plug>MarkSearchNext
441 "nmap  # <Plug>MarkSearchPrev
442 " }}}
443 " Gundo ------------------------------------------------------------------- {{{
444 "    nnoremap <F5> :GundoToggle<CR>
445 " }}}
446 " Bookmarks --------------------------------------------------------------- {{{
447
448 let g:bookmark_save_per_working_dir = 1
449 let g:bookmark_auto_close = 1
450 let g:bookmark_auto_save = 1
451 " unmap the default mapping in plugins
452 nmap <Plug>DisableBookmarkToggle        <Plug>BookmarkToggle
453 nmap <Plug>DisableBookmarkAnnotate      <Plug>BookmarkAnnotate
454 nmap <Plug>DisableBookmarkShowAll       <Plug>BookmarkShowAll
455 nmap <Plug>DisableBookmarkNext          <Plug>BookmarkNext
456 nmap <Plug>DisableBookmarkPrev          <Plug>BookmarkPrev
457 nmap <Plug>DisableBookmarkClear         <Plug>BookmarkClear
458 nmap <Plug>DisableBookmarkClearAll      <Plug>BookmarkClearAll
459 " remapping
460 nmap mm <Plug>BookmarkToggle
461 "  nmap ,i <Plug>BookmarkAnnotate
462 nmap \m <Plug>BookmarkShowAll
463 let g:bookmark_center = 1
464 let g:bookmark_auto_close = 1
465 "let g:bookmark_highlight_lines = 1
466 "  nmap ,j <Plug>BookmarkNext
467 "  nmap ,k <Plug>BookmarkPrev
468 "  nmap ,c <Plug>BookmarkClear
469 "  nmap ,x <Plug>BookmarkClearAll
470 " }}}
471 " EasyMotion -------------------------------------------------------------- {{{
472 map en <Plug>(easymotion-sn)
473 map ej <Plug>(easymotion-j)
474 map ek <Plug>(easymotion-k)
475 map eb <Plug>(easymotion-b)
476 map ew <Plug>(easymotion-w)
477 map ee <Plug>(easymotion-w)
478 map el <Plug>(easymotion-lineforward)
479 map eh <Plug>(easymotion-linebackward)
480
481 "map <SPACE>n <Plug>(easymotion-sn)
482 "map <SPACE>j <Plug>(easymotion-j)
483 "map <SPACE>k <Plug>(easymotion-k)
484 "map <SPACE>b <Plug>(easymotion-b)
485 "map <SPACE>w <Plug>(easymotion-w)
486 "map <SPACE>e <Plug>(easymotion-w)
487 "map <SPACE>l <Plug>(easymotion-lineforward)
488 "map <SPACE>h <Plug>(easymotion-linebackward)
489
490 "" }}}
491 " vim-latex --------------------------------------------------------------- {{{
492 "set grepprg=grep\ -nH\ $*
493 "let g:tex_flavor='latex'
494 "set iskeyword+=:
495 "autocmd BufEnter *.tex set sw=2
496 "disable default mapping 
497 imap #$ <Plug>IMAP_JumpForward
498 nmap #$ <Plug>IMAP_JumpForward
499 vmap #$ <Plug>IMAP_JumpForward
500 vmap #$ <Plug>IMAP_DeleteAndJumpForward
501 let g:Imap_FreezeImap=1
502 " }}}
503 " }}}
504 " FileType ---------------------------------------------------------------- {{{
505 autocmd BufNewFile,BufRead *.log set filetype=logecc
506 autocmd BufNewFile,BufRead *.log.[0-9] set filetype=logecc
507 autocmd BufNewFile,BufRead *tmux.conf set filetype=tmux
508 autocmd BufNewFile,BufRead SConstruct set filetype=python
509 autocmd BufNewFile,BufRead SConscript* set filetype=python
510 autocmd BufNewFile,BufReadPost *.md set filetype=markdown
511 autocmd BufNewFile,BufRead *.c set filetype=cpp
512
513 " http://vim.wikia.com/wiki/Update_the_diff_view_automatically
514 autocmd InsertLeave,BufWritePost,CursorHold * if &diff == 1 | diffupdate | endif
515 " setlocal nomodifiable for svn diff
516 autocmd BufWinEnter *.svn-base setlocal nomodifiable 
517
518 autocmd WinEnter * nnoremap <buffer> gj @=(&diff)?']czz':'gj'<CR> |
519         \ nnoremap <buffer> gk @=(&diff)?'[czz':'gk'<CR>
520
521 autocmd FileType qf nnoremap <buffer> <silent> q :q<CR> | setlocal nowrap | setlocal nocursorline
522 autocmd FileType help nnoremap <buffer> <silent> q :q<CR> | vertical resize 85;
523 autocmd FileType c,cpp setlocal foldmethod=syntax |
524     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("\"", "{}") |
525         \ inoremap <buffer> { {<CR>}<ESC>kA<CR>|
526     \ nnoremap <buffer> <silent> <C-]> :let word=expand("<cword>")<CR>:wincmd o<cr>:vsp<CR>:exec("tag ". word)<cr>zzzr:wincmd w<cr>
527 autocmd FileType python setlocal foldmethod=indent |
528     \ set list
529
530 autocmd FileType xml setlocal foldmethod=syntax |
531         \ let g:xml_syntax_folding=1
532 autocmd FileType vim setlocal foldmethod=marker |
533         \ setlocal formatoptions-=c formatoptions-=r formatoptions-=o |
534     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("", "{} \"")
535
536 autocmd FileType perl setlocal foldmethod=syntax |
537     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("\"", "{}") |
538         \ inoremap <buffer> {<CR> {<CR>}<ESC>kA<CR>
539
540 autocmd Filetype markdown setlocal textwidth=80
541
542 autocmd CmdwinEnter * map <buffer> q :q<CR>
543
544 " }}}
545 " Functions --------------------------------------------------------------- {{{
546 " DiffOrig ---------------------------------------------------------------- {{{
547 " refert vimrc_example.vim 
548 " Convenient command to see the difference between the current buffer and the
549 " file it was loaded from, thus the changes you made.
550 " Only define it when not defined already.
551 if !exists(":DiffOrig")
552   command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
553                   \ | wincmd p | diffthis
554 endif 
555 " }}}
556 " Fold Quickfix ----------------------------------------------------------- {{{
557 "http://vim.wikia.com/wiki/Show_only_lines_in_quickfix_list_for_current_buffer 
558 if ! exists('g:foldmisses_context')
559   let g:foldmisses_context = 0
560 endif
561
562 " Add manual fold from line1 to line2, inclusive.
563 function! s:Fold(line1, line2)
564   if a:line1 < a:line2
565     execute a:line1.','.a:line2.'fold'
566   endif
567 endfunction
568
569 " Return list of line numbers for current buffer found in quickfix list.
570 function! s:GetHitLineNumbers(list)
571   let result = []
572   for d in a:list
573     if d.valid && d.bufnr == bufnr('')
574       call add(result, d.lnum)
575     endif
576   endfor
577   return result
578 endfunction
579
580 function! s:FoldMisses(list, context)
581   setlocal foldmethod=manual
582   normal! zE
583   let extra = a:context == 99999 ? g:foldmisses_context : a:context
584   let last = 0
585   for lnum in s:GetHitLineNumbers(a:list)
586 "    let start = last==0 ? 1 : last+extra
587     let start = last==0 ? 1 : last+1+extra
588     call s:Fold(start, lnum-1-extra)
589     let last = lnum
590   endfor
591   call s:Fold(last+1+extra, line('$'))
592 "  call s:Fold(last+extra, line('$'))
593 endfunction
594
595 ":[N]FoldMisses [N]     Show only the lines (and surrounding [N] lines
596 ":[N]FoldLMisses [N]    of context) in the current buffer that appear
597 "                       in the quickfix / location list.
598 "                       Missed, error-free lines are folded away.
599 command! -bar -count=99999 FoldMisses call s:FoldMisses(getqflist(), <count>)
600 command! -bar -count=99999 FoldLMisses call s:FoldMisses(getloclist(0), <count>)
601 " }}}
602 " ToggleList -------------------------------------------------------------- {{{
603 "http://vim.wikia.com/wiki/Toggle_to_open_or_close_the_quickfix_window
604 function! GetBufferList()
605   redir =>buflist
606   silent! ls
607   redir END
608   return buflist
609 endfunction
610
611 function! ToggleList(bufname, pfx)
612   let buflist = GetBufferList()
613   for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
614     if bufwinnr(bufnum) != -1
615       exec(a:pfx.'close')
616       return
617     endif
618   endfor
619   if a:pfx == 'l' && len(getloclist(0)) == 0
620       echohl ErrorMsg
621       echo "Location List is Empty."
622       return
623   endif
624   let winnr = winnr()
625   exec(a:pfx.'open')
626   if winnr() != winnr
627     wincmd p
628   endif
629 endfunction
630
631 nmap <silent> \l :call ToggleList("Location List", 'l')<CR>
632 nmap <silent> \q :call ToggleList("Quickfix List", 'c')<CR>
633 " }}}
634 " DiffToggle -------------------------------------------------------------- {{{
635 "if !exists(":DiffToggle")
636 "       \ endif
637 "endif
638 function! DiffToggle()
639         if(&diff)
640                 diffoff | wincmd l | :q
641         else
642                 exec ":VCSVimDiff" | wincmd h
643         endif
644 endfunction
645 nnoremap \d :call DiffToggle()<CR>
646 "noremap <Leader>d      @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
647 " }}}
648
649 " }}}
650
651 "nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
652 nnoremap <silent> <cr> @=(foldlevel('.')?'za':"\<Space>")<CR>
653 "noremap <Leader>d      @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
654
655 " https://bitbucket.org/sjl/dotfiles/src/tip/vim/vimrc
656 " Make sure Vim returns to the same line when you reopen a file.
657 " Thanks, Amit
658 augroup line_return
659     au!
660     au BufReadPost *
661         \ if line("'\"") > 0 && line("'\"") <= line("$") |
662         \     execute 'normal! g`"zvzz' |
663         \ endif
664 augroup END
665
666 iabbrev  -...  <C-R>=repeat('-', 80 - col(".") - 4 ) . " {{{"
667 iabbrev         "}   " }}}
668
669 " $ sed -n l
670 " to show the key sequence when pressing some key, 
671 " such as Ctrl-V
672 " cnfile
673 " cpfile
674
675
676 " some prefix for mapping
677 " <Leader> = ;
678 " ,
679 " \
680 " m
681 nnoremap B ^
682 nnoremap E $
683 nnoremap <C-N>  :cn<CR>zzzv
684 nnoremap <C-P>  :cp<CR>zzzv
685 "http://dougblack.io/words/a-good-vimrc.html
686 "nnoremap gV `[v`]
687
688 "nnoremap <silent> <C-]> :let word=expand("<cword>")<CR>:vsp<CR>:wincmd w<cr>:exec("tag ". word)<cr>
689 "nnoremap <silent> <C-]> :let word=expand("<cword>")<CR>:wincmd o<cr>:vsp<CR>:exec("tag ". word)<cr>zz:wincmd w<cr>
690 " command in normal mode, and visual mode
691 " yiw  = viwy
692 " diw  = viwd
693 " gn   select search and in visual mode
694 " confirm when using :q to quit the last tab page,
695 "Alias q if\ winnr('$')>1||tabpagenr('$')>1||confirm('Really\ quit?',\ "&OK\\n&Cancel")==1|quit|endif
696
697
698
699 " color of current line
700 "let s:marklist = ''
701 nnoremap <Leader>m  :marks abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<CR>:normal '
702
703 "let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript',
704 "                          \ 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
705
706
707 "" TODO: 
708 ""