Emacs - config
[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>  <S-Left>
203 inoremap <C-f>  <S-Right>
204 imap <A-d>      <S-Right><C-w>
205 " }}}
206 " Command mode ------------------------------------------------------- {{{
207 cmap jj         <C-c>
208 cnoremap <C-A>  <Home>
209 cnoremap <C-E>  <End>
210 cnoremap <C-B>  <Left>
211 cnoremap <C-F>  <Right>
212 cnoremap <C-D>  <Del>
213
214
215 if has("gui_running")
216 " only for Macvim <D-Left> D is Command key
217         cmap <A-a>      <D-Left>
218         cmap <A-e>      <D-Right>
219
220         cnoremap <A-b>  <S-Left>
221         cnoremap <A-f>  <S-Right>
222         cnoremap <A-d>  <S-Right><S-Right><S-Left><C-w>
223 else
224         cnoremap \eb     <S-Left>
225         cnoremap \ef     <S-Right>
226         cnoremap \ed     <S-Right><S-Right><S-Left><C-w>
227 endif
228 " delet a word left of cursor
229 cmap <S-BS>     <C-w>
230 " }}}
231 " Visual mode ------------------------------------------------------------- {{{
232 "" key mapping for  visul mode
233 vmap <C-k>      {       
234 vmap <C-j>      }       
235 "vmap <Leader>y "*y
236 vmap Y  "*y
237 "
238 "vmap <C-Y>  "qy
239 "vmap <C-P>  "qp
240 vnoremap    Y   "*y
241 vnoremap    <Leader>p  "*p
242 "search for visually selectecd text
243 vnoremap // y/<C-R>"<CR>
244 vnoremap <Leader>a  :
245 " }}}
246 " }}}
247 " Plugins Configuration --------------------------------------------------- {{{
248 " Fuzzy Finder ------------------------------------------------------------ {{{
249 let g:fuf_modesDisable = []
250 let g:fuf_mrufile_maxItem = 400
251 let g:fuf_mrucmd_maxItem = 400
252 let g:fuf_file_exclude = '\v\~$|\.(DS_Store|o|exe|dll|bak|orig|swp|pyc)$|(^|[/\\])\.(hg|git|bzr|svn)($|[/\\])'
253 let g:fuf_buffertag_ctagsPath = '/usr/local/bin/ctags'
254 let g:fuf_enumeratingLimit = 30
255 nnoremap <silent> sj     :FufBuffer<CR>
256 nnoremap <silent> sk     :FufFileWithCurrentBufferDir<CR>
257 nnoremap <silent> sK     :FufFileWithFullCwd<CR>
258 nnoremap <silent> s<C-k> :FufFile<CR>
259 "nnoremap <silent> sl     :FufCoverageFileChange<CR>
260 "nnoremap <silent> sL     :FufCoverageFileChange<CR>
261 "nnoremap <silent> s<C-l> :FufCoverageFileRegister<CR>
262 nnoremap <silent> sd     :FufDirWithCurrentBufferDir<CR>
263 nnoremap <silent> sD     :FufDirWithFullCwd<CR>
264 nnoremap <silent> s<C-d> :FufDir<CR>
265 nnoremap <silent> sn     :FufMruFile<CR>
266 nnoremap <silent> sN     :FufMruFileInCwd<CR>
267 nnoremap <silent> sm     :FufMruCmd<CR>
268 "nnoremap <silent> su     :FufBookmarkFile<CR>
269 nnoremap <silent> s<C-u> :FufBookmarkFileAdd<CR>
270 "vnoremap <silent> s<C-u> :FufBookmarkFileAddAsSelectedText<CR>
271 nnoremap <silent> si     :FufBookmarkDir<CR>
272 nnoremap <silent> s<C-i> :FufBookmarkDirAdd<CR>
273 nnoremap <silent> sT     :FufTag<CR>
274 nnoremap <silent> st     :FufTag!<CR>
275 nnoremap <silent> s<C-]> :FufTagWithCursorWord!<CR>
276 nnoremap <silent> s,     :FufBufferTag<CR>
277 nnoremap <silent> s<     :FufBufferTag!<CR>
278 "vnoremap <silent> s,     :FufBufferTagWithSelectedText!<CR>
279 "vnoremap <silent> s<     :FufBufferTagWithSelectedText<CR>
280 nnoremap <silent> s}     :FufBufferTagWithCursorWord!<CR>
281 nnoremap <silent> sl     :FufBufferTagAll<CR>
282 "nnoremap <silent> s.     :FufBufferTagAll<CR>
283 nnoremap <silent> s>     :FufBufferTagAll!<CR>
284 "vnoremap <silent> s.     :FufBufferTagAllWithSelectedText!<CR>
285 "vnoremap <silent> s>     :FufBufferTagAllWithSelectedText<CR>
286 "nnoremap <silent> s]     :FufBufferTagAllWithCursorWord!<CR>
287 nnoremap <silent> sG     :FufTaggedFile<CR>
288 nnoremap <silent> sg     :FufTaggedFile!<CR>
289 "nnoremap <silent> so     :FufJumpList<CR>
290 "nnoremap <silent> sp     :FufChangeList<CR>
291 "nnoremap <silent> sq     :FufQuickfix<CR>
292 "nnoremap <silent> sy     :FufLine<CR>
293 "  nnoremap <silent> sh     :FufHelp<CR>
294 "nnoremap <silent> se     :FufEditDataFile<CR>
295 nnoremap <silent> sr     :FufRenewCache<CR>
296 " }}}
297 " YouCompleteMe ----------------------------------------------------------- {{{
298 "syntax on, must before the YCM,
299
300 " Load YouCompleteMe only on OSX
301 if !has("osx")
302     let g:loaded_youcompleteme = 1
303 endif
304
305 "let g:ycm_collect_identifiers_from_tags_files = 1
306 let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
307 " this is fix youcompleteme python error
308 "http://www.cnblogs.com/clivelee/p/4266559.html
309 "https://github.com/Valloric/YouCompleteMe/issues/18
310 "let g:ycm_path_to_python_interpreter= '/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
311 let g:ycm_auto_trigger = 1
312 let g:ycm_seed_identifiers_with_syntax = 1
313 let g:ycm_show_diagnostics_ui = 0
314 let g:ycm_enable_diagnostic_signs = 0
315 set completeopt-=preview   " disable preview windows for completion
316 let g:ycm_confirm_extra_conf = 0
317 " delete default mapping for <leader>d
318 let g:ycm_key_detailed_diagnostics = ''
319
320 " }}}
321 " Airline ----------------------------------------------------------------- {{{
322 "if has("gui_running")
323
324   let g:airline_mode_map = {
325       \ '__' : '-',
326       \ 'n'  : 'N',
327       \ 'i'  : 'I',
328       \ 'R'  : 'R',
329       \ 'c'  : 'C',
330       \ 'v'  : 'V',
331       \ 'V'  : 'V',
332       \ '\16' : 'V',
333       \ 's'  : 'S',
334       \ 'S'  : 'S',
335       \ '\13' : 'S',
336       \ }
337
338         let g:airline_theme = 'badwolf'
339
340 "if has("gui_running")
341         let g:airline_powerline_fonts=1
342         let g:airline_left_sep = ''
343         let g:airline_left_alt_sep = ''
344         let g:airline_right_sep = ''
345         let g:airline_right_alt_sep = ''
346
347 "       let g:airline#extensions#tabline#show_buffers = 1
348         let g:airline#extensions#tabline#show_buffers = 0
349         let g:airline#extensions#tabline#enabled = 1
350         let g:airline#extensions#tabline#left_sep = ''
351         let g:airline#extensions#tabline#left_alt_sep =''
352         let g:airline#extensions#tagbar#enabled = 1
353 "else 
354 "       let g:airline_powerline_fonts=1
355 "       let g:airline_left_sep = ''
356 ""      let g:airline_left_alt_sep = ''
357 "       let g:airline_right_sep = ''
358 ""      let g:airline_right_alt_sep = ''
359 "
360 "       let g:airline#extensions#tabline#show_buffers = 0
361 "       let g:airline#extensions#tabline#enabled = 1
362 "       let g:airline#extensions#tabline#left_sep = ''
363 ""      let g:airline#extensions#tabline#left_alt_sep =''
364 "       let g:airline#extensions#tagbar#enabled = 1
365 "endif
366         "
367 "       let g:airline_section_a = 'N'
368         let g:airline_section_b = '%f%m'
369         let g:airline_section_c = ''
370         let g:airline_section_x = '[%-.50{CurDir()}]'
371         let g:airline_section_y = '%y'
372         let g:airline_section_z = '%c, %l/%L %p%%'
373         let g:airline_section_warning = '' " (syntastic, whitespace)
374
375 set laststatus=2
376 set statusline=\ %<%F%m%=[%-.50{CurDir()}]\ %y\ %c,\ %l/%L\ \ %p%%\ 
377 function! CurDir()
378         let curdir = substitute(getcwd(), $HOME, "~", "g")
379         return curdir
380 endfunction
381
382 "endif
383 " }}}
384 " NerdTree ---------------------------------------------------------------- {{{
385 " Fix keymapping conflict
386 nmap <unique> <Leader>, <Plug>MarkClear
387 nmap <Leader>n  :NERDTreeToggle<CR>
388 nmap <Leader>N  :NERDTreeFind<CR>
389 " }}}
390 " AutoClose --------------------------------------------------------------- {{{
391 let g:AutoCloseProtectedRegions = ["Dialog", "ThoughBubble"]
392 " }}}
393 " TagBar ------------------------------------------------------------------ {{{
394 noremap <Leader>f       :TagbarToggle<CR><C-w>l
395 let Tlist_Ctags_Cmd="/usr/local/bin/ctags"
396 " }}}
397 " Tcd --------------------------------------------------------------------- {{{
398 cabbrev cd Tcd
399 " }}}
400 " cmdline-completion ------------------------------------------------------ {{{
401 "http://foocoder.com/blog/mei-ri-vimcha-jian-suo-jin-xian-shi-vim-indent-guides.html/
402 cmap <C-J> <Plug>CmdlineCompletionBackward
403 cmap <C-K> <Plug>CmdlineCompletionForward
404 " }}}
405 " VSCCommand -------------------------------------------------------------- {{{
406 "" ==============  VCSCommand.vim =====================
407 "let VCSCommandSVKExec='disabled no such executable'
408 let VCSCommandDeleteOnHide=1    
409 let VCSCommandDisableMappings=1
410 "let VCSCommandEnableBufferSetup=1
411 "nmap <Leader>sd        :VCSVimDiff<CR>
412 augroup VCSCommand
413         autocmd User VCSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr> | setlocal nomodifiable
414 augroup END
415 nmap <Leader>dg         :diffget<CR>
416 " }}}
417 " YankRing ---------------------------------------------------------------- {{{
418 let g:yankring_min_element_length = 2
419 nmap \r :YRShow<CR>
420 let g:yankring_replace_n_pkey = '<A->>'
421 let g:yankring_replace_n_nkey = '<A-<>'
422 let g:yankring_history_dir = "$HOME/.vim/temp/"
423 " }}}
424 " Gtags ------------------------------------------------------------------- {{{
425 if has("gui_running")
426         noremap <A-.> :Gtags<CR>
427         noremap <A-r> :Gtags -r<CR>
428         noremap <A-o> :Gtags -s<CR>
429         noremap <A-g> :Gtags -g<CR> 
430 else
431         noremap \e. :Gtags<CR>
432         noremap \er :Gtags -r<CR>
433 "       noremap j :Gtags -s<CR>
434         noremap \eg :Gtags -g<CR> 
435 endif
436 " }}}
437 " Marks ------------------------------------------------------------------- {{{
438 nmap  \h <Plug>MarkSet
439 "nmap  * <Plug>MarkSearchNext
440 "nmap  # <Plug>MarkSearchPrev
441 " }}}
442 " Gundo ------------------------------------------------------------------- {{{
443 "    nnoremap <F5> :GundoToggle<CR>
444 " }}}
445 " Bookmarks --------------------------------------------------------------- {{{
446
447 let g:bookmark_save_per_working_dir = 1
448 let g:bookmark_auto_close = 1
449 let g:bookmark_auto_save = 1
450 " unmap the default mapping in plugins
451 nmap <Plug>DisableBookmarkToggle        <Plug>BookmarkToggle
452 nmap <Plug>DisableBookmarkAnnotate      <Plug>BookmarkAnnotate
453 nmap <Plug>DisableBookmarkShowAll       <Plug>BookmarkShowAll
454 nmap <Plug>DisableBookmarkNext          <Plug>BookmarkNext
455 nmap <Plug>DisableBookmarkPrev          <Plug>BookmarkPrev
456 nmap <Plug>DisableBookmarkClear         <Plug>BookmarkClear
457 nmap <Plug>DisableBookmarkClearAll      <Plug>BookmarkClearAll
458 " remapping
459 nmap mm <Plug>BookmarkToggle
460 "  nmap ,i <Plug>BookmarkAnnotate
461 nmap \m <Plug>BookmarkShowAll
462 let g:bookmark_center = 1
463 let g:bookmark_auto_close = 1
464 "let g:bookmark_highlight_lines = 1
465 "  nmap ,j <Plug>BookmarkNext
466 "  nmap ,k <Plug>BookmarkPrev
467 "  nmap ,c <Plug>BookmarkClear
468 "  nmap ,x <Plug>BookmarkClearAll
469 " }}}
470 " EasyMotion -------------------------------------------------------------- {{{
471 map en <Plug>(easymotion-sn)
472 map ej <Plug>(easymotion-j)
473 map ek <Plug>(easymotion-k)
474 map eb <Plug>(easymotion-b)
475 map ew <Plug>(easymotion-w)
476 map ee <Plug>(easymotion-w)
477 map el <Plug>(easymotion-lineforward)
478 map eh <Plug>(easymotion-linebackward)
479
480 "map <SPACE>n <Plug>(easymotion-sn)
481 "map <SPACE>j <Plug>(easymotion-j)
482 "map <SPACE>k <Plug>(easymotion-k)
483 "map <SPACE>b <Plug>(easymotion-b)
484 "map <SPACE>w <Plug>(easymotion-w)
485 "map <SPACE>e <Plug>(easymotion-w)
486 "map <SPACE>l <Plug>(easymotion-lineforward)
487 "map <SPACE>h <Plug>(easymotion-linebackward)
488
489 "" }}}
490 " vim-latex --------------------------------------------------------------- {{{
491 "set grepprg=grep\ -nH\ $*
492 "let g:tex_flavor='latex'
493 "set iskeyword+=:
494 "autocmd BufEnter *.tex set sw=2
495 "disable default mapping 
496 imap #$ <Plug>IMAP_JumpForward
497 nmap #$ <Plug>IMAP_JumpForward
498 vmap #$ <Plug>IMAP_JumpForward
499 vmap #$ <Plug>IMAP_DeleteAndJumpForward
500 let g:Imap_FreezeImap=1
501 " }}}
502 " }}}
503 " FileType ---------------------------------------------------------------- {{{
504 autocmd BufNewFile,BufRead *.log set filetype=logecc
505 autocmd BufNewFile,BufRead *.log.[0-9] set filetype=logecc
506 autocmd BufNewFile,BufRead *tmux.conf set filetype=tmux
507 autocmd BufNewFile,BufRead SConstruct set filetype=python
508 autocmd BufNewFile,BufRead SConscript* set filetype=python
509 autocmd BufNewFile,BufReadPost *.md set filetype=markdown
510 autocmd BufNewFile,BufRead *.c set filetype=cpp
511
512 " http://vim.wikia.com/wiki/Update_the_diff_view_automatically
513 autocmd InsertLeave,BufWritePost,CursorHold * if &diff == 1 | diffupdate | endif
514 " setlocal nomodifiable for svn diff
515 autocmd BufWinEnter *.svn-base setlocal nomodifiable 
516
517 autocmd WinEnter * nnoremap <buffer> gj @=(&diff)?']czz':'gj'<CR> |
518         \ nnoremap <buffer> gk @=(&diff)?'[czz':'gk'<CR>
519
520 autocmd FileType qf nnoremap <buffer> <silent> q :q<CR> | setlocal nowrap | setlocal nocursorline
521 autocmd FileType help nnoremap <buffer> <silent> q :q<CR> | vertical resize 85;
522 autocmd FileType c,cpp setlocal foldmethod=syntax |
523     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("\"", "{}") |
524         \ inoremap <buffer> { {<CR>}<ESC>kA<CR>|
525     \ nnoremap <buffer> <silent> <C-]> :let word=expand("<cword>")<CR>:wincmd o<cr>:vsp<CR>:exec("tag ". word)<cr>zzzr:wincmd w<cr>
526 autocmd FileType python setlocal foldmethod=indent |
527     \ set list
528
529 autocmd FileType xml setlocal foldmethod=syntax |
530         \ let g:xml_syntax_folding=1
531 autocmd FileType vim setlocal foldmethod=marker |
532         \ setlocal formatoptions-=c formatoptions-=r formatoptions-=o |
533     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("", "{} \"")
534
535 autocmd FileType perl setlocal foldmethod=syntax |
536     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("\"", "{}") |
537         \ inoremap <buffer> {<CR> {<CR>}<ESC>kA<CR>
538
539 autocmd Filetype markdown setlocal textwidth=80
540
541 autocmd CmdwinEnter * map <buffer> q :q<CR>
542
543 " }}}
544 " Functions --------------------------------------------------------------- {{{
545 " DiffOrig ---------------------------------------------------------------- {{{
546 " refert vimrc_example.vim 
547 " Convenient command to see the difference between the current buffer and the
548 " file it was loaded from, thus the changes you made.
549 " Only define it when not defined already.
550 if !exists(":DiffOrig")
551   command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
552                   \ | wincmd p | diffthis
553 endif 
554 " }}}
555 " Fold Quickfix ----------------------------------------------------------- {{{
556 "http://vim.wikia.com/wiki/Show_only_lines_in_quickfix_list_for_current_buffer 
557 if ! exists('g:foldmisses_context')
558   let g:foldmisses_context = 0
559 endif
560
561 " Add manual fold from line1 to line2, inclusive.
562 function! s:Fold(line1, line2)
563   if a:line1 < a:line2
564     execute a:line1.','.a:line2.'fold'
565   endif
566 endfunction
567
568 " Return list of line numbers for current buffer found in quickfix list.
569 function! s:GetHitLineNumbers(list)
570   let result = []
571   for d in a:list
572     if d.valid && d.bufnr == bufnr('')
573       call add(result, d.lnum)
574     endif
575   endfor
576   return result
577 endfunction
578
579 function! s:FoldMisses(list, context)
580   setlocal foldmethod=manual
581   normal! zE
582   let extra = a:context == 99999 ? g:foldmisses_context : a:context
583   let last = 0
584   for lnum in s:GetHitLineNumbers(a:list)
585 "    let start = last==0 ? 1 : last+extra
586     let start = last==0 ? 1 : last+1+extra
587     call s:Fold(start, lnum-1-extra)
588     let last = lnum
589   endfor
590   call s:Fold(last+1+extra, line('$'))
591 "  call s:Fold(last+extra, line('$'))
592 endfunction
593
594 ":[N]FoldMisses [N]     Show only the lines (and surrounding [N] lines
595 ":[N]FoldLMisses [N]    of context) in the current buffer that appear
596 "                       in the quickfix / location list.
597 "                       Missed, error-free lines are folded away.
598 command! -bar -count=99999 FoldMisses call s:FoldMisses(getqflist(), <count>)
599 command! -bar -count=99999 FoldLMisses call s:FoldMisses(getloclist(0), <count>)
600 " }}}
601 " ToggleList -------------------------------------------------------------- {{{
602 "http://vim.wikia.com/wiki/Toggle_to_open_or_close_the_quickfix_window
603 function! GetBufferList()
604   redir =>buflist
605   silent! ls
606   redir END
607   return buflist
608 endfunction
609
610 function! ToggleList(bufname, pfx)
611   let buflist = GetBufferList()
612   for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
613     if bufwinnr(bufnum) != -1
614       exec(a:pfx.'close')
615       return
616     endif
617   endfor
618   if a:pfx == 'l' && len(getloclist(0)) == 0
619       echohl ErrorMsg
620       echo "Location List is Empty."
621       return
622   endif
623   let winnr = winnr()
624   exec(a:pfx.'open')
625   if winnr() != winnr
626     wincmd p
627   endif
628 endfunction
629
630 nmap <silent> \l :call ToggleList("Location List", 'l')<CR>
631 nmap <silent> \q :call ToggleList("Quickfix List", 'c')<CR>
632 " }}}
633 " DiffToggle -------------------------------------------------------------- {{{
634 "if !exists(":DiffToggle")
635 "       \ endif
636 "endif
637 function! DiffToggle()
638         if(&diff)
639                 diffoff | wincmd l | :q
640         else
641                 exec ":VCSVimDiff" | wincmd h
642         endif
643 endfunction
644 nnoremap \d :call DiffToggle()<CR>
645 "noremap <Leader>d      @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
646 " }}}
647
648 " }}}
649
650 "nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
651 nnoremap <silent> <cr> @=(foldlevel('.')?'za':"\<Space>")<CR>
652 "noremap <Leader>d      @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
653
654 " https://bitbucket.org/sjl/dotfiles/src/tip/vim/vimrc
655 " Make sure Vim returns to the same line when you reopen a file.
656 " Thanks, Amit
657 augroup line_return
658     au!
659     au BufReadPost *
660         \ if line("'\"") > 0 && line("'\"") <= line("$") |
661         \     execute 'normal! g`"zvzz' |
662         \ endif
663 augroup END
664
665 iabbrev  -...  <C-R>=repeat('-', 80 - col(".") - 4 ) . " {{{"
666 iabbrev         "}   " }}}
667
668 " $ sed -n l
669 " to show the key sequence when pressing some key, 
670 " such as Ctrl-V
671 " cnfile
672 " cpfile
673
674
675 " some prefix for mapping
676 " <Leader> = ;
677 " ,
678 " \
679 " m
680 nnoremap B ^
681 nnoremap E $
682 nnoremap <C-N>  :cn<CR>zzzv
683 nnoremap <C-P>  :cp<CR>zzzv
684 "http://dougblack.io/words/a-good-vimrc.html
685 "nnoremap gV `[v`]
686
687 "nnoremap <silent> <C-]> :let word=expand("<cword>")<CR>:vsp<CR>:wincmd w<cr>:exec("tag ". word)<cr>
688 "nnoremap <silent> <C-]> :let word=expand("<cword>")<CR>:wincmd o<cr>:vsp<CR>:exec("tag ". word)<cr>zz:wincmd w<cr>
689 " command in normal mode, and visual mode
690 " yiw  = viwy
691 " diw  = viwd
692 " gn   select search and in visual mode
693 " confirm when using :q to quit the last tab page,
694 "Alias q if\ winnr('$')>1||tabpagenr('$')>1||confirm('Really\ quit?',\ "&OK\\n&Cancel")==1|quit|endif
695
696
697
698 " color of current line
699 "let s:marklist = ''
700 nnoremap <Leader>m  :marks abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<CR>:normal '
701
702 "let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript',
703 "                          \ 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
704
705
706 "" TODO: 
707 ""