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