Vim: Close All Buffers But This One

前端 未结 13 2233
别那么骄傲
别那么骄傲 2020-12-22 15:04

How can I close all buffers in Vim except the one I am currently editing?

相关标签:
13条回答
  • 2020-12-22 16:00

    Closing all open buffers:

    silent! execute "1,".bufnr("$")."bd"
    

    Closing all open buffers except for the current one:

    function! CloseAllBuffersButCurrent()
      let curr = bufnr("%")
      let last = bufnr("$")
    
      if curr > 1    | silent! execute "1,".(curr-1)."bd"     | endif
      if curr < last | silent! execute (curr+1).",".last."bd" | endif
    endfunction
    

    Add this function to .vimrc and call it using :call CloseAllBuffersButCurrent().

    Convenience map:

    nmap <Leader>\c :call CloseAllBuffersButCurrent()<CR>
    
    0 讨论(0)
提交回复
热议问题