-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffers.vim
43 lines (35 loc) · 929 Bytes
/
buffers.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
" A buffer becomes hidden when it is abandoned
set hidden
" Navigate buffers
nnoremap <C-Left> :bprev<CR>
nnoremap <C-Right> :bnext<CR>
nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprev<CR>
" Close the current buffer
map <leader>bd :Bclose<CR>
map <C-d> :Bclose<CR>
" Close all the buffers
map <leader>ba :1,1000 bd!<CR>
" Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:currentBufNum) && getbufvar(l:currentBufNum, "&mod")
echohl ErrorMsg
echo bufname(l:currentBufNum).' is modified'
echohl None
return 1
endif
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete ".l:currentBufNum)
endif
endfunction