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