Vim: Close All Buffers But This One

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

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

相关标签:
13条回答
  • 2020-12-22 15:54

    I put this in my .vimrc file

    nnoremap <leader>ca :w <bar> %bd <bar> e# <bar> bd# <CR>
    

    then your leader + ca (close all) close all the buffers except the current one.

    What it does is

    :w - save current buffer

    %bd - close all the buffers

    e# - open last edited file

    bd# - close the unnamed buffer

    0 讨论(0)
  • 2020-12-22 15:54

    There's a plugin that does exactly this and a bit more!

    Check out close-buffers.vim

    0 讨论(0)
  • 2020-12-22 15:56

    Try this

    bufdo bd
    

    bufdo runs command for all buffers

    http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers

    0 讨论(0)
  • 2020-12-22 15:56

    I do this

    :w | %bd | e#
    

    My favorite if I just want my current buffer open and close all others.

    How it works: first write current buffer's changes, then close all open buffers, then reopen the buffer I was currently on. In Vim, the | chains the execution of commands together. If your buffer is up to date the above can be shortened to :%bd | e#

    0 讨论(0)
  • 2020-12-22 15:56

    Note: As mentioned in the comments, this closes windows and not buffers.

    By using

    :on[ly][!]
    

    and

    :h only
    
    0 讨论(0)
  • 2020-12-22 15:57

    How about just:

    ctrl-w o
    

    (thanks to https://thoughtbot.com/blog/vim-splits-move-faster-and-more-naturally)

    0 讨论(0)
提交回复
热议问题