djwhitt (owner)

Revisions

gist: 180716 Download_button fork
public
Public Clone URL: git://gist.github.com/180716.git
Embed All Files: show embed
Text only #
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
function! <SID>BufcloseCloseIt()
    let l:currentBufNum = bufnr("%")
    let l:alternateBufNum = bufnr("#")
 
    if buflisted(l:alternateBufNum)
        buffer #
    else
        " this try-catch block is disgusting
        try
            bprev
        catch /.*/ " catch if we can't switch to previous
        endtry
    endif
 
    if bufnr("%") == l:currentBufNum
        new
    endif
 
    if bufloaded(l:currentBufNum)
        execute("bdelete! ".l:currentBufNum)
    endif
endfunction
 
command! Bclose call <SID>BufcloseCloseIt()