comparison vimrc @ 146:3333853b8bbe

Use airline - tabline for buffer management
author zegervdv <zegervdv@me.com>
date Thu, 16 Oct 2014 00:40:11 +0200
parents 6b108f5f26fc
children 0d420021bd5d
comparison
equal deleted inserted replaced
145:b3fd48f2df2c 146:3333853b8bbe
104 104
105 " When editing a file, always jump to the last known cursor position. 105 " When editing a file, always jump to the last known cursor position.
106 " Don't do it for commit messages, when the position is invalid, or when 106 " Don't do it for commit messages, when the position is invalid, or when
107 " inside an event handler (happens when dropping a file on gvim). 107 " inside an event handler (happens when dropping a file on gvim).
108 autocmd BufReadPost * 108 autocmd BufReadPost *
109 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | 109 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
110 \ exe "normal g`\"" | 110 \ exe "normal g`\"" |
111 \ endif 111 \ endif
112 112
113 " Set leader to , 113 " Set leader to ,
114 let mapleader = "," 114 let mapleader = ","
115 115
116 " See long lines as line breaks 116 " See long lines as line breaks
118 map k gk 118 map k gk
119 119
120 " remap tag-search to better place 120 " remap tag-search to better place
121 " nmap <C-$> <C-]> 121 " nmap <C-$> <C-]>
122 function! JumpToTagInSplit() 122 function! JumpToTagInSplit()
123 execute "normal! \<c-w>v\<c-]>mzzMzvzz15\<c-e>" 123 execute "normal! \<c-w>v\<c-]>mzzMzvzz15\<c-e>"
124 execute "keepjumps normal! `z" 124 execute "keepjumps normal! `z"
125 Pulse 125 Pulse
126 endfunction 126 endfunction
127 nnoremap <C-$> :silent! call JumpToTagInSplit()<CR> 127 nnoremap <C-$> :silent! call JumpToTagInSplit()<CR>
128 128
129 " Jump to end of line in insert mode 129 " Jump to end of line in insert mode
130 inoremap <C-a> <C-o>I 130 inoremap <C-a> <C-o>I
140 " Jump out of inner bracket 140 " Jump out of inner bracket
141 inoremap <C-f> <ESC>%%a 141 inoremap <C-f> <ESC>%%a
142 142
143 " Switch between the last two files 143 " Switch between the last two files
144 nnoremap <SPACE><SPACE> <C-^> 144 nnoremap <SPACE><SPACE> <C-^>
145 " Move between buffers
146 nnoremap gb :bnext<CR>
147 nnoremap gB :bprevious<CR>
145 148
146 " Very Magic search patterns 149 " Very Magic search patterns
147 nmap / /\v 150 nmap / /\v
148 cmap s/ s/\v 151 cmap s/ s/\v
149 152
180 " Briefly change colour of last highlight 183 " Briefly change colour of last highlight
181 " nnoremap <silent> n n:call HLNext(0.4)<cr> 184 " nnoremap <silent> n n:call HLNext(0.4)<cr>
182 " nnoremap <silent> N N:call HLNext(0.4)<cr> 185 " nnoremap <silent> N N:call HLNext(0.4)<cr>
183 186
184 function! HLNext (blinktime) 187 function! HLNext (blinktime)
185 highlight WhiteOnRed ctermfg=white ctermbg=red guifg=white guibg=red 188 highlight WhiteOnRed ctermfg=white ctermbg=red guifg=white guibg=red
186 let [bufnum, lnum, col, off] = getpos('.') 189 let [bufnum, lnum, col, off] = getpos('.')
187 let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/)) 190 let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/))
188 let target_pat = '\c\%#'.@/ 191 let target_pat = '\c\%#'.@/
189 let ring = matchadd('WhiteOnRed', target_pat, 101) 192 let ring = matchadd('WhiteOnRed', target_pat, 101)
190 redraw 193 redraw
191 exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm' 194 exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
192 call matchdelete(ring) 195 call matchdelete(ring)
193 redraw 196 redraw
194 endfunction 197 endfunction
195 198
196 " Highlight matching parenthesis in different color so I don't mess up 199 " Highlight matching parenthesis in different color so I don't mess up
197 hi MatchParen cterm=underline ctermbg=none ctermfg=white gui=underline guibg=black guifg=white 200 hi MatchParen cterm=underline ctermbg=none ctermfg=white gui=underline guibg=black guifg=white
198 201
212 " Keep selection when shifting 215 " Keep selection when shifting
213 vmap <expr> > KeepVisualSelection(">") 216 vmap <expr> > KeepVisualSelection(">")
214 vmap <expr> < KeepVisualSelection("<") 217 vmap <expr> < KeepVisualSelection("<")
215 218
216 function! KeepVisualSelection(cmd) 219 function! KeepVisualSelection(cmd)
217 set nosmartindent 220 set nosmartindent
218 if mode() ==# "V" 221 if mode() ==# "V"
219 return a:cmd . ":set smartindent\<CR>gv" 222 return a:cmd . ":set smartindent\<CR>gv"
220 else 223 else
221 return a:cmd . ":set smartindent\<CR>" 224 return a:cmd . ":set smartindent\<CR>"
222 endif 225 endif
223 endfunction 226 endfunction
224 227
225 let g:indent_guides_auto_colors = 0 228 let g:indent_guides_auto_colors = 0
226 let g:indent_guides_guide_size = 1 229 let g:indent_guides_guide_size = 1
227 highlight IndentGuidesEven guibg=background 230 highlight IndentGuidesEven guibg=background
243 inoremap <C-u> <esc>mzgUiw`za 246 inoremap <C-u> <esc>mzgUiw`za
244 247
245 nnoremap <leader>ev :vsplit $MYVIMRC<cr> 248 nnoremap <leader>ev :vsplit $MYVIMRC<cr>
246 249
247 function! MyFoldText() " {{{ 250 function! MyFoldText() " {{{
248 let line = getline(v:foldstart) 251 let line = getline(v:foldstart)
249 252
250 let nucolwidth = &fdc + &number * &numberwidth 253 let nucolwidth = &fdc + &number * &numberwidth
251 let windowwidth = winwidth(0) - nucolwidth - 3 254 let windowwidth = winwidth(0) - nucolwidth - 3
252 let foldedlinecount = v:foldend - v:foldstart 255 let foldedlinecount = v:foldend - v:foldstart
253 256
254 " expand tabs into spaces 257 " expand tabs into spaces
255 let onetab = strpart(' ', 0, &tabstop) 258 let onetab = strpart(' ', 0, &tabstop)
256 let line = substitute(line, '\t', onetab, 'g') 259 let line = substitute(line, '\t', onetab, 'g')
257 260
258 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) 261 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
259 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) 262 let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
260 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' 263 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
261 endfunction " }}} 264 endfunction " }}}
262 set foldtext=MyFoldText() 265 set foldtext=MyFoldText()
263 266
264 " Next and Last {{{ 267 " Next and Last {{{
265 " 268 "
303 onoremap il :<c-u>call <SID>NextTextObject('i', '?')<cr> 306 onoremap il :<c-u>call <SID>NextTextObject('i', '?')<cr>
304 xnoremap il :<c-u>call <SID>NextTextObject('i', '?')<cr> 307 xnoremap il :<c-u>call <SID>NextTextObject('i', '?')<cr>
305 308
306 309
307 function! s:NextTextObject(motion, dir) 310 function! s:NextTextObject(motion, dir)
308 let c = nr2char(getchar()) 311 let c = nr2char(getchar())
309 let d = '' 312 let d = ''
310 313
311 if c ==# "b" || c ==# "(" || c ==# ")" 314 if c ==# "b" || c ==# "(" || c ==# ")"
312 let c = "(" 315 let c = "("
313 elseif c ==# "B" || c ==# "{" || c ==# "}" 316 elseif c ==# "B" || c ==# "{" || c ==# "}"
314 let c = "{" 317 let c = "{"
315 elseif c ==# "r" || c ==# "[" || c ==# "]" 318 elseif c ==# "r" || c ==# "[" || c ==# "]"
316 let c = "[" 319 let c = "["
320 elseif c ==# "'"
321 let c = "'"
322 elseif c ==# '"'
323 let c = '"'
324 else
325 return
326 endif
327
328 " Find the next opening-whatever.
329 execute "normal! " . a:dir . c . "\<cr>"
330
331 if a:motion ==# 'a'
332 " If we're doing an 'around' method, we just need to select around it
333 " and we can bail out to Vim.
334 execute "normal! va" . c
335 else
336 " Otherwise we're looking at an 'inside' motion. Unfortunately these
337 " get tricky when you're dealing with an empty set of delimiters because
338 " Vim does the wrong thing when you say vi(.
339
340 let open = ''
341 let close = ''
342
343 if c ==# "("
344 let open = "("
345 let close = ")"
346 elseif c ==# "{"
347 let open = "{"
348 let close = "}"
349 elseif c ==# "["
350 let open = "\\["
351 let close = "\\]"
317 elseif c ==# "'" 352 elseif c ==# "'"
318 let c = "'" 353 let open = "'"
354 let close = "'"
319 elseif c ==# '"' 355 elseif c ==# '"'
320 let c = '"' 356 let open = '"'
357 let close = '"'
358 endif
359
360 " We'll start at the current delimiter.
361 let start_pos = getpos('.')
362 let start_l = start_pos[1]
363 let start_c = start_pos[2]
364
365 " Then we'll find it's matching end delimiter.
366 if c ==# "'" || c ==# '"'
367 " searchpairpos() doesn't work for quotes, because fuck me.
368 let end_pos = searchpos(open)
321 else 369 else
322 return 370 let end_pos = searchpairpos(open, '', close)
323 endif 371 endif
324 372
325 " Find the next opening-whatever. 373 let end_l = end_pos[0]
326 execute "normal! " . a:dir . c . "\<cr>" 374 let end_c = end_pos[1]
327 375
328 if a:motion ==# 'a' 376 call setpos('.', start_pos)
329 " If we're doing an 'around' method, we just need to select around it 377
330 " and we can bail out to Vim. 378 if start_l == end_l && start_c == (end_c - 1)
331 execute "normal! va" . c 379 " We're in an empty set of delimiters. We'll append an "x"
380 " character and select that so most Vim commands will do something
381 " sane. v is gonna be weird, and so is y. Oh well.
382 execute "normal! ax\<esc>\<left>"
383 execute "normal! vi" . c
384 elseif start_l == end_l && start_c == (end_c - 2)
385 " We're on a set of delimiters that contain a single, non-newline
386 " character. We can just select that and we're done.
387 execute "normal! vi" . c
332 else 388 else
333 " Otherwise we're looking at an 'inside' motion. Unfortunately these 389 " Otherwise these delimiters contain something. But we're still not
334 " get tricky when you're dealing with an empty set of delimiters because 390 " sure Vim's gonna work, because if they contain nothing but
335 " Vim does the wrong thing when you say vi(. 391 " newlines Vim still does the wrong thing. So we'll manually select
336 392 " the guts ourselves.
337 let open = '' 393 let whichwrap = &whichwrap
338 let close = '' 394 set whichwrap+=h,l
339 395
340 if c ==# "(" 396 execute "normal! va" . c . "hol"
341 let open = "(" 397
342 let close = ")" 398 let &whichwrap = whichwrap
343 elseif c ==# "{"
344 let open = "{"
345 let close = "}"
346 elseif c ==# "["
347 let open = "\\["
348 let close = "\\]"
349 elseif c ==# "'"
350 let open = "'"
351 let close = "'"
352 elseif c ==# '"'
353 let open = '"'
354 let close = '"'
355 endif
356
357 " We'll start at the current delimiter.
358 let start_pos = getpos('.')
359 let start_l = start_pos[1]
360 let start_c = start_pos[2]
361
362 " Then we'll find it's matching end delimiter.
363 if c ==# "'" || c ==# '"'
364 " searchpairpos() doesn't work for quotes, because fuck me.
365 let end_pos = searchpos(open)
366 else
367 let end_pos = searchpairpos(open, '', close)
368 endif
369
370 let end_l = end_pos[0]
371 let end_c = end_pos[1]
372
373 call setpos('.', start_pos)
374
375 if start_l == end_l && start_c == (end_c - 1)
376 " We're in an empty set of delimiters. We'll append an "x"
377 " character and select that so most Vim commands will do something
378 " sane. v is gonna be weird, and so is y. Oh well.
379 execute "normal! ax\<esc>\<left>"
380 execute "normal! vi" . c
381 elseif start_l == end_l && start_c == (end_c - 2)
382 " We're on a set of delimiters that contain a single, non-newline
383 " character. We can just select that and we're done.
384 execute "normal! vi" . c
385 else
386 " Otherwise these delimiters contain something. But we're still not
387 " sure Vim's gonna work, because if they contain nothing but
388 " newlines Vim still does the wrong thing. So we'll manually select
389 " the guts ourselves.
390 let whichwrap = &whichwrap
391 set whichwrap+=h,l
392
393 execute "normal! va" . c . "hol"
394
395 let &whichwrap = whichwrap
396 endif
397 endif 399 endif
400 endif
398 endfunction 401 endfunction
399 " }}} 402 " }}}
400 " VHDL ctags 403 " VHDL ctags
401 let g:tlist_vhdl_settings = 'vhdl;d:package declarations;b:package bodies;e:entities;a:architecture specifications;t:type declarations;p:processes;f:functions;r:procedures' 404 let g:tlist_vhdl_settings = 'vhdl;d:package declarations;b:package bodies;e:entities;a:architecture specifications;t:type declarations;p:processes;f:functions;r:procedures'
402 " }}} 405 " }}}
421 let g:airline_theme = 'base16' 424 let g:airline_theme = 'base16'
422 else 425 else
423 let g:airline_theme = 'tomorrow' 426 let g:airline_theme = 'tomorrow'
424 endif 427 endif
425 let g:airline#extensions#syntastic#enabled = 1 428 let g:airline#extensions#syntastic#enabled = 1
429 let g:airline#extensions#tabline#enabled = 1
430 let g:airline#extensions#tabline#fnamemod = ':t'
431 let g:airline#extensions#tabline#left_sep = ''
432 let g:airline#extensions#tabline#left_alt_sep = ''
433 let g:airline#extensions#tabline#right_sep = ''
434 let g:airline#extensions#tabline#right_alt_sep = ''
426 " }}} 435 " }}}
427 " Unite {{{ 436 " Unite {{{
428 call unite#filters#matcher_default#use(['matcher_fuzzy','matcher_regexp']) 437 call unite#filters#matcher_default#use(['matcher_fuzzy','matcher_regexp'])
429 call unite#filters#sorter_default#use(['sorter_rank']) 438 call unite#filters#sorter_default#use(['sorter_rank'])
430 " call unite#set_profile('files', 'smartcase', 1) 439 " call unite#set_profile('files', 'smartcase', 1)
431 call unite#custom#profile('files', 'context.smartcase', 1) 440 call unite#custom#profile('files', 'context.smartcase', 1)
432 call unite#custom#source('line,outline', 'matchers', 'matcher_fuzzy') 441 call unite#custom#source('line,outline', 'matchers', 'matcher_fuzzy')
433 call unite#custom#source( 'buffer', 'converters', ['converter_file_directory']) 442 call unite#custom#source( 'buffer', 'converters', ['converter_file_directory'])
434 " sort file results by length 443 " sort file results by length
435 call unite#custom#source('file', 'sorters', 'sorter_length') 444 call unite#custom#source('file', 'sorters', 'sorter_length')
436 call unite#custom#source('file_rec/async', 'sorters', 'sorter_length') 445 call unite#custom#source('file_rec/async', 'sorters', 'sorter_length')
437 let g:unite_enable_start_insert=0 446 let g:unite_enable_start_insert=0
438 let g:unite_source_history_yank_enable=1 447 let g:unite_source_history_yank_enable=1
439 let g:unite_source_rec_max_cache_files=3000 448 let g:unite_source_rec_max_cache_files=3000
440 let g:unite_prompt='» ' 449 let g:unite_prompt='» '
441 if executable('ag') 450 if executable('ag')
442 let g:unite_source_grep_command = 'ag' 451 let g:unite_source_grep_command = 'ag'
443 let g:unite_source_grep_default_opts = 452 let g:unite_source_grep_default_opts =
444 \ '-i --line-numbers --nocolor --nogroup --hidden --ignore ' . 453 \ '-i --line-numbers --nocolor --nogroup --hidden --ignore ' .
445 \ '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr''' 454 \ '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
446 let g:unite_source_grep_recursive_opt = '' 455 let g:unite_source_grep_recursive_opt = ''
447 let g:unite_source_rec_async_command = 'ag --nocolor --nogroup --hidden -g ""' 456 let g:unite_source_rec_async_command = 'ag --nocolor --nogroup --hidden -g ""'
448 elseif executable('ack') 457 elseif executable('ack')
449 let g:unite_source_grep_command='ack' 458 let g:unite_source_grep_command='ack'
450 let g:unite_source_grep_default_opts='--no-heading --no-color -C4' 459 let g:unite_source_grep_default_opts='--no-heading --no-color -C4'
451 let g:unite_source_grep_recursive_opt='' 460 let g:unite_source_grep_recursive_opt=''
452 endif 461 endif
453 function! s:unite_settings() 462 function! s:unite_settings()
454 nmap <buffer> Q <plug>(unite_exit) 463 nmap <buffer> Q <plug>(unite_exit)
455 nmap <buffer> <esc> <plug>(unite_exit) 464 nmap <buffer> <esc> <plug>(unite_exit)
456 imap <buffer> <C-j> <Plug>(unite_select_next_line) 465 imap <buffer> <C-j> <Plug>(unite_select_next_line)
457 imap <buffer> <C-k> <Plug>(unite_select_previous_line) 466 imap <buffer> <C-k> <Plug>(unite_select_previous_line)
458 endfunction 467 endfunction
459 autocmd FileType unite call s:unite_settings() 468 autocmd FileType unite call s:unite_settings()
460 469
461 nnoremap <silent> <SPACE>m :<C-u>Unite -auto-preview -buffer-name=recent file_mru<cr> 470 nnoremap <silent> <SPACE>m :<C-u>Unite -auto-preview -buffer-name=recent file_mru<cr>
462 nnoremap <silent> <SPACE>y :<C-u>Unite -buffer-name=yanks history/yank<cr> 471 nnoremap <silent> <SPACE>y :<C-u>Unite -buffer-name=yanks history/yank<cr>
463 nnoremap <silent> <SPACE>l :<C-u>Unite -start-insert -auto-resize -buffer-name=line line<cr> 472 nnoremap <silent> <SPACE>l :<C-u>Unite -start-insert -auto-resize -buffer-name=line line<cr>
464 nnoremap <silent> <SPACE>b :<C-u>Unite everything/async<cr> 473 nnoremap <silent> <SPACE>b :<C-u>Unite everything/async<cr>
465 nnoremap <silent> <SPACE>/ :<C-u>Unite -no-quit -buffer-name=search grep:.<cr> 474 nnoremap <silent> <SPACE>/ :<C-u>Unite -no-quit -buffer-name=search grep:.<cr>
466 nnoremap <silent> <SPACE>k :<C-u>Unite -auto-resize -buffer-name=mappings mapping<cr> 475 nnoremap <silent> <SPACE>k :<C-u>Unite -auto-resize -buffer-name=mappings mapping<cr>
467 nnoremap <silent> <SPACE>s :<C-u>Unite -quick-match buffer<cr> 476 nnoremap <silent> <SPACE>s :<C-u>Unite -quick-match buffer<cr>
468 nnoremap <silent> <SPACE>o :<C-u>Unite outline<CR> 477 nnoremap <silent> <SPACE>o :<C-u>Unite outline<CR>
469 nnoremap <silent> <SPACE>t :<C-u>Unite tag<CR> 478 nnoremap <silent> <SPACE>t :<C-u>Unite tag<CR>
470 nnoremap <silent> <C-p> :<C-u>Unite -start-insert file_rec/async buffer<CR> 479 nnoremap <silent> <C-p> :<C-u>Unite -start-insert file_rec/async buffer<CR>
471 nnoremap <silent> <SPACE>h :<C-u>Unite ssh://Hurricane/STM-Quadcopter/source<CR> 480 nnoremap <silent> <SPACE>h :<C-u>Unite ssh://Hurricane/STM-Quadcopter/source<CR>
472 nnoremap <silent> <SPACE>i :<C-u>Unite ssh://imac-van-zeger.local/Documents<CR> 481 nnoremap <silent> <SPACE>i :<C-u>Unite ssh://imac-van-zeger.local/Documents<CR>
473 " }}} 482 " }}}
474 " Unite Build {{{ 483 " Unite Build {{{
475 " TODO: Create builders eg Latex, Vagrant? 484 " TODO: Create builders eg Latex, Vagrant?
476 " }}} 485 " }}}
477 " Vimfiler {{{ 486 " Vimfiler {{{