Added general buffers configuration and mappings

This commit is contained in:
Emmanuel BENOîT 2015-03-08 08:58:22 +01:00
parent 099a3b3645
commit 864ec3b152
2 changed files with 50 additions and 0 deletions

46
cfg/15-buffers.vim Normal file
View file

@ -0,0 +1,46 @@
set hidden " Don't close buffers
" Buffer navigation
nnoremap <silent> <S-Left> :bprev<CR>
nnoremap <silent> <S-Right> :bnext<CR>
" Close buffer
function <SID>CloseCurrentBuffer( )
let btarget = bufnr( '%' )
if getbufvar( l:btarget , '&modified' )
echohl ErrorMsg
echomsg "No write since last change"
echohl NONE
return
endif
let wnums = filter( range( 1 , winnr( '$' ) ) ,
\ 'winbufnr(v:val) == btarget' )
let wcurrent = winnr( )
for w in l:wnums
execute l:w . "wincmd w"
let prevbuf = bufnr( '#' )
if l:prevbuf > 0 && buflisted( l:prevbuf ) && l:prevbuf != w
buffer #
else
bprevious
endif
if btarget == bufnr('%')
let blisted = filter( range( 1 , bufnr( '$' ) ) ,
\ 'buflisted( v:val ) && v:val != btarget' )
let bhidden = filter( copy( l:blisted ) ,
\ 'bufwinnr( v:val ) < 0' )
let bjump = ( l:bhidden + l:blisted + [ -1 ] )[ 0 ]
if l:bjump > 0
execute 'buffer ' . l:bjump
else
enew
endif
endif
endfor
execute 'bdelete' l:btarget
execute l:wcurrent . 'wincmd w'
endfunction
nnoremap <silent> <C-S-Down> :call <SID>CloseCurrentBuffer()<CR>

View file

@ -22,6 +22,10 @@ local leader key.
<Leader>T Toggle visible tabs
<S-Left> Previous buffer
<S-Right> Next buffer
<C-S-Down> Close current buffer
<A-Insert> Open new tab
<C-A-Insert> Close current tab
<A-Left> Select previous tab