How can I close a buffer without closing the window?

前端 未结 16 1032
鱼传尺愫
鱼传尺愫 2020-12-12 13:35

Vim\'s multilayered views (Windows, Buffers and Tabs) left me a little confused. Let\'s say I split the display (:sp) and then select a different buffer to display in each w

16条回答
  •  一个人的身影
    2020-12-12 13:48

    nmap d :bprevious:bdelete #
    

    Works as it should until one buffer is open in several windows. Good enough unless you want to use the bigger scripts out there.

    Edit: this is what i use right now:

    function! BufferDelete()
        if &modified
            echohl ErrorMsg
            echomsg "No write since last change. Not closing buffer."
            echohl NONE
        else
            let s:total_nr_buffers = len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
    
            if s:total_nr_buffers == 1
                bdelete
                echo "Buffer deleted. Created new buffer."
            else
                bprevious
                bdelete #
                echo "Buffer deleted."
            endif
        endif
    endfunction
    

提交回复
热议问题