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