如何关闭所有未显示在 vim 窗口中的缓冲区? [英] How do I close all buffers that aren't shown in a window in vim?

查看:28
本文介绍了如何关闭所有未显示在 vim 窗口中的缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 vim 中打开了一大群缓冲区,其中只有少数在拆分窗口或其他选项卡上打开.有没有办法关闭除当前在这些拆分或选项卡之一中可见的所有内容之外的所有内容?

I have a horde of buffers open in vim, with only a few of them open in split windows or on other tabs. Is there a way to close all but the ones that are currently visible in one of those splits or tabs?

推荐答案

这里有一个替代解决方案,你可以放在 .vimrc 中:

Here's an alternative solution you can drop in your .vimrc:

function! Wipeout()
  " list of *all* buffer numbers
  let l:buffers = range(1, bufnr('$'))

  " what tab page are we in?
  let l:currentTab = tabpagenr()
  try
    " go through all tab pages
    let l:tab = 0
    while l:tab < tabpagenr('$')
      let l:tab += 1

      " go through all windows
      let l:win = 0
      while l:win < winnr('$')
        let l:win += 1
        " whatever buffer is in this window in this tab, remove it from
        " l:buffers list
        let l:thisbuf = winbufnr(l:win)
        call remove(l:buffers, index(l:buffers, l:thisbuf))
      endwhile
    endwhile

    " if there are any buffers left, delete them
    if len(l:buffers)
      execute 'bwipeout' join(l:buffers)
    endif
  finally
    " go back to our original tab page
    execute 'tabnext' l:currentTab
  endtry
endfunction

使用:调用Wipeout().

这篇关于如何关闭所有未显示在 vim 窗口中的缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆