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