vimrc - correct gui font setting
[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=Source\ Code\ Pro\ 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 " Fix keymapping conflict
380 nmap <unique> <Leader>, <Plug>MarkClear
381 nmap <Leader>n  :NERDTreeToggle<CR>
382 nmap <Leader>N  :NERDTreeFind<CR>
383 " }}}
384 " AutoClose --------------------------------------------------------------- {{{
385 let g:AutoCloseProtectedRegions = ["Dialog", "ThoughBubble"]
386 " }}}
387 " TagBar ------------------------------------------------------------------ {{{
388 noremap <Leader>f       :TagbarToggle<CR><C-w>l
389 let Tlist_Ctags_Cmd="/usr/local/bin/ctags"
390 " }}}
391 " Tcd --------------------------------------------------------------------- {{{
392 cabbrev cd Tcd
393 " }}}
394 " cmdline-completion ------------------------------------------------------ {{{
395 "http://foocoder.com/blog/mei-ri-vimcha-jian-suo-jin-xian-shi-vim-indent-guides.html/
396 cmap <C-J> <Plug>CmdlineCompletionBackward
397 cmap <C-K> <Plug>CmdlineCompletionForward
398 " }}}
399 " VSCCommand -------------------------------------------------------------- {{{
400 "" ==============  VCSCommand.vim =====================
401 "let VCSCommandSVKExec='disabled no such executable'
402 let VCSCommandDeleteOnHide=1    
403 let VCSCommandDisableMappings=1
404 "let VCSCommandEnableBufferSetup=1
405 "nmap <Leader>sd        :VCSVimDiff<CR>
406 augroup VCSCommand
407         autocmd User VCSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr> | setlocal nomodifiable
408 augroup END
409 nmap <Leader>dg         :diffget<CR>
410 " }}}
411 " YankRing ---------------------------------------------------------------- {{{
412 let g:yankring_min_element_length = 2
413 nmap \r :YRShow<CR>
414 let g:yankring_replace_n_pkey = '<A->>'
415 let g:yankring_replace_n_nkey = '<A-<>'
416 let g:yankring_history_dir = "$HOME/.vim/temp/"
417 " }}}
418 " Gtags ------------------------------------------------------------------- {{{
419 if has("gui_running")
420         noremap <A-.> :Gtags<CR>
421         noremap <A-r> :Gtags -r<CR>
422         noremap <A-o> :Gtags -s<CR>
423         noremap <A-g> :Gtags -g<CR> 
424 else
425         noremap \e. :Gtags<CR>
426         noremap \er :Gtags -r<CR>
427 "       noremap j :Gtags -s<CR>
428         noremap \eg :Gtags -g<CR> 
429 endif
430 " }}}
431 " Marks ------------------------------------------------------------------- {{{
432 nmap  \h <Plug>MarkSet
433 "nmap  * <Plug>MarkSearchNext
434 "nmap  # <Plug>MarkSearchPrev
435 " }}}
436 " Gundo ------------------------------------------------------------------- {{{
437 "    nnoremap <F5> :GundoToggle<CR>
438 " }}}
439 " Bookmarks --------------------------------------------------------------- {{{
440
441 let g:bookmark_save_per_working_dir = 1
442 let g:bookmark_auto_close = 1
443 let g:bookmark_auto_save = 1
444 " unmap the default mapping in plugins
445 nmap <Plug>DisableBookmarkToggle        <Plug>BookmarkToggle
446 nmap <Plug>DisableBookmarkAnnotate      <Plug>BookmarkAnnotate
447 nmap <Plug>DisableBookmarkShowAll       <Plug>BookmarkShowAll
448 nmap <Plug>DisableBookmarkNext          <Plug>BookmarkNext
449 nmap <Plug>DisableBookmarkPrev          <Plug>BookmarkPrev
450 nmap <Plug>DisableBookmarkClear         <Plug>BookmarkClear
451 nmap <Plug>DisableBookmarkClearAll      <Plug>BookmarkClearAll
452 " remapping
453 nmap mm <Plug>BookmarkToggle
454 "  nmap ,i <Plug>BookmarkAnnotate
455 nmap \m <Plug>BookmarkShowAll
456 let g:bookmark_center = 1
457 let g:bookmark_auto_close = 1
458 "let g:bookmark_highlight_lines = 1
459 "  nmap ,j <Plug>BookmarkNext
460 "  nmap ,k <Plug>BookmarkPrev
461 "  nmap ,c <Plug>BookmarkClear
462 "  nmap ,x <Plug>BookmarkClearAll
463 " }}}
464 " EasyMotion -------------------------------------------------------------- {{{
465 map en <Plug>(easymotion-sn)
466 map ej <Plug>(easymotion-j)
467 map ek <Plug>(easymotion-k)
468 map eb <Plug>(easymotion-b)
469 map ew <Plug>(easymotion-w)
470 map ee <Plug>(easymotion-w)
471 map el <Plug>(easymotion-lineforward)
472 map eh <Plug>(easymotion-linebackward)
473
474 "map <SPACE>n <Plug>(easymotion-sn)
475 "map <SPACE>j <Plug>(easymotion-j)
476 "map <SPACE>k <Plug>(easymotion-k)
477 "map <SPACE>b <Plug>(easymotion-b)
478 "map <SPACE>w <Plug>(easymotion-w)
479 "map <SPACE>e <Plug>(easymotion-w)
480 "map <SPACE>l <Plug>(easymotion-lineforward)
481 "map <SPACE>h <Plug>(easymotion-linebackward)
482
483 "" }}}
484 " vim-latex --------------------------------------------------------------- {{{
485 "set grepprg=grep\ -nH\ $*
486 "let g:tex_flavor='latex'
487 "set iskeyword+=:
488 "autocmd BufEnter *.tex set sw=2
489 "disable default mapping 
490 imap #$ <Plug>IMAP_JumpForward
491 nmap #$ <Plug>IMAP_JumpForward
492 vmap #$ <Plug>IMAP_JumpForward
493 vmap #$ <Plug>IMAP_DeleteAndJumpForward
494 let g:Imap_FreezeImap=1
495 " }}}
496 " }}}
497 " FileType ---------------------------------------------------------------- {{{
498 autocmd BufNewFile,BufRead *.log set filetype=logecc
499 autocmd BufNewFile,BufRead *.log.[0-9] set filetype=logecc
500 autocmd BufNewFile,BufRead *tmux.conf set filetype=tmux
501 autocmd BufNewFile,BufRead SConstruct set filetype=python
502 autocmd BufNewFile,BufRead SConscript* set filetype=python
503 autocmd BufNewFile,BufReadPost *.md set filetype=markdown
504 autocmd BufNewFile,BufRead *.c set filetype=cpp
505
506 " http://vim.wikia.com/wiki/Update_the_diff_view_automatically
507 autocmd InsertLeave,BufWritePost,CursorHold * if &diff == 1 | diffupdate | endif
508 " setlocal nomodifiable for svn diff
509 autocmd BufWinEnter *.svn-base setlocal nomodifiable 
510
511 autocmd WinEnter * nnoremap <buffer> gj @=(&diff)?']czz':'gj'<CR> |
512         \ nnoremap <buffer> gk @=(&diff)?'[czz':'gk'<CR>
513
514 autocmd FileType qf nnoremap <buffer> <silent> q :q<CR> | setlocal nowrap | setlocal nocursorline
515 autocmd FileType help nnoremap <buffer> <silent> q :q<CR> | vertical resize 85;
516 autocmd FileType c,cpp setlocal foldmethod=syntax |
517     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("\"", "{}") |
518         \ inoremap <buffer> { {<CR>}<ESC>kA<CR>|
519     \ nnoremap <buffer> <silent> <C-]> :let word=expand("<cword>")<CR>:wincmd o<cr>:vsp<CR>:exec("tag ". word)<cr>zzzr:wincmd w<cr>
520 autocmd FileType python setlocal foldmethod=indent |
521     \ set list
522
523 autocmd FileType xml setlocal foldmethod=syntax |
524         \ let g:xml_syntax_folding=1
525 autocmd FileType vim setlocal foldmethod=marker |
526         \ setlocal formatoptions-=c formatoptions-=r formatoptions-=o |
527     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("", "{} \"")
528
529 autocmd FileType perl setlocal foldmethod=syntax |
530     \ let b:AutoClosePairs = AutoClose#DefaultPairsModified("\"", "{}") |
531         \ inoremap <buffer> {<CR> {<CR>}<ESC>kA<CR>
532
533 autocmd Filetype markdown setlocal textwidth=80
534
535 autocmd CmdwinEnter * map <buffer> q :q<CR>
536
537 " }}}
538 " Functions --------------------------------------------------------------- {{{
539 " DiffOrig ---------------------------------------------------------------- {{{
540 " refert vimrc_example.vim 
541 " Convenient command to see the difference between the current buffer and the
542 " file it was loaded from, thus the changes you made.
543 " Only define it when not defined already.
544 if !exists(":DiffOrig")
545   command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
546                   \ | wincmd p | diffthis
547 endif 
548 " }}}
549 " Fold Quickfix ----------------------------------------------------------- {{{
550 "http://vim.wikia.com/wiki/Show_only_lines_in_quickfix_list_for_current_buffer 
551 if ! exists('g:foldmisses_context')
552   let g:foldmisses_context = 0
553 endif
554
555 " Add manual fold from line1 to line2, inclusive.
556 function! s:Fold(line1, line2)
557   if a:line1 < a:line2
558     execute a:line1.','.a:line2.'fold'
559   endif
560 endfunction
561
562 " Return list of line numbers for current buffer found in quickfix list.
563 function! s:GetHitLineNumbers(list)
564   let result = []
565   for d in a:list
566     if d.valid && d.bufnr == bufnr('')
567       call add(result, d.lnum)
568     endif
569   endfor
570   return result
571 endfunction
572
573 function! s:FoldMisses(list, context)
574   setlocal foldmethod=manual
575   normal! zE
576   let extra = a:context == 99999 ? g:foldmisses_context : a:context
577   let last = 0
578   for lnum in s:GetHitLineNumbers(a:list)
579 "    let start = last==0 ? 1 : last+extra
580     let start = last==0 ? 1 : last+1+extra
581     call s:Fold(start, lnum-1-extra)
582     let last = lnum
583   endfor
584   call s:Fold(last+1+extra, line('$'))
585 "  call s:Fold(last+extra, line('$'))
586 endfunction
587
588 ":[N]FoldMisses [N]     Show only the lines (and surrounding [N] lines
589 ":[N]FoldLMisses [N]    of context) in the current buffer that appear
590 "                       in the quickfix / location list.
591 "                       Missed, error-free lines are folded away.
592 command! -bar -count=99999 FoldMisses call s:FoldMisses(getqflist(), <count>)
593 command! -bar -count=99999 FoldLMisses call s:FoldMisses(getloclist(0), <count>)
594 " }}}
595 " ToggleList -------------------------------------------------------------- {{{
596 "http://vim.wikia.com/wiki/Toggle_to_open_or_close_the_quickfix_window
597 function! GetBufferList()
598   redir =>buflist
599   silent! ls
600   redir END
601   return buflist
602 endfunction
603
604 function! ToggleList(bufname, pfx)
605   let buflist = GetBufferList()
606   for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
607     if bufwinnr(bufnum) != -1
608       exec(a:pfx.'close')
609       return
610     endif
611   endfor
612   if a:pfx == 'l' && len(getloclist(0)) == 0
613       echohl ErrorMsg
614       echo "Location List is Empty."
615       return
616   endif
617   let winnr = winnr()
618   exec(a:pfx.'open')
619   if winnr() != winnr
620     wincmd p
621   endif
622 endfunction
623
624 nmap <silent> \l :call ToggleList("Location List", 'l')<CR>
625 nmap <silent> \q :call ToggleList("Quickfix List", 'c')<CR>
626 " }}}
627 " DiffToggle -------------------------------------------------------------- {{{
628 "if !exists(":DiffToggle")
629 "       \ endif
630 "endif
631 function! DiffToggle()
632         if(&diff)
633                 diffoff | wincmd l | :q
634         else
635                 exec ":VCSVimDiff" | wincmd h
636         endif
637 endfunction
638 nnoremap \d :call DiffToggle()<CR>
639 "noremap <Leader>d      @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
640 " }}}
641
642 " }}}
643
644 "nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
645 nnoremap <silent> <cr> @=(foldlevel('.')?'za':"\<Space>")<CR>
646 "noremap <Leader>d      @=(&diff)?':diffoff':":VCSVimDiff"<CR><CR>
647
648 " https://bitbucket.org/sjl/dotfiles/src/tip/vim/vimrc
649 " Make sure Vim returns to the same line when you reopen a file.
650 " Thanks, Amit
651 augroup line_return
652     au!
653     au BufReadPost *
654         \ if line("'\"") > 0 && line("'\"") <= line("$") |
655         \     execute 'normal! g`"zvzz' |
656         \ endif
657 augroup END
658
659 iabbrev  -...  <C-R>=repeat('-', 80 - col(".") - 4 ) . " {{{"
660 iabbrev         "}   " }}}
661
662 " $ sed -n l
663 " to show the key sequence when pressing some key, 
664 " such as Ctrl-V
665 " cnfile
666 " cpfile
667
668
669 " some prefix for mapping
670 " <Leader> = ;
671 " ,
672 " \
673 " m
674 nnoremap B ^
675 nnoremap E $
676 nnoremap <C-N>  :cn<CR>zzzv
677 nnoremap <C-P>  :cp<CR>zzzv
678 "http://dougblack.io/words/a-good-vimrc.html
679 "nnoremap gV `[v`]
680
681 "nnoremap <silent> <C-]> :let word=expand("<cword>")<CR>:vsp<CR>:wincmd w<cr>:exec("tag ". word)<cr>
682 "nnoremap <silent> <C-]> :let word=expand("<cword>")<CR>:wincmd o<cr>:vsp<CR>:exec("tag ". word)<cr>zz:wincmd w<cr>
683 " command in normal mode, and visual mode
684 " yiw  = viwy
685 " diw  = viwd
686 " gn   select search and in visual mode
687 " confirm when using :q to quit the last tab page,
688 "Alias q if\ winnr('$')>1||tabpagenr('$')>1||confirm('Really\ quit?',\ "&OK\\n&Cancel")==1|quit|endif
689
690
691
692 " color of current line
693 "let s:marklist = ''
694 nnoremap <Leader>m  :marks abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<CR>:normal '
695
696 "let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript',
697 "                          \ 'undo', 'line', 'changes', 'mixed', 'bookmarkdir']
698
699
700 "" TODO: 
701 ""