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