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