English 中文(简体)
Vim:Buffers But
原标题:Vim: Close All Buffers But This One
  • 时间:2010-12-28 10:14:27
  •  标签:
  • vim

除了我目前正在编辑的缓冲外,我如何能够在维姆关闭所有的缓冲?

最佳回答
问题回答

我非常容易地这样做:

:%bd|e#

如果你不关心目前的问题,那么做像(不需要说明)这样的事情就更加简单:

1,100bd

:w | %bd | e#

如果我只想打开我目前的缓冲地带,结束所有其他事情,我会投赞成票。

如何开展工作:首先写当前的缓冲变化,然后关闭所有开放的缓冲地带,然后,我现在重新开放。 在Vim,>/code>链条共同执行指挥。 如果您的缓冲时间已经更新,上述时间可缩短到<条码>:%bd >>>>>>>>><#>/code>。

依靠Janruiz的回答。

改变你想要保持的缓冲,然后

:1,1000bd

指挥<条码>bd(删除)将不会删除任何未经改动的缓冲区。 这样,你就可以把目前(变换)档案保留在缓冲清单中。

Edit: Please notice that this will also delete your NERDTreeBuffer. You can get it back with :NERDTree

我在我的档案中这样做。

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

之后,<条码>铅+卡(全部)除现时外,关闭所有缓冲器。

What it does is

:w - 拯救目前的缓冲

%bd - 关闭所有缓冲地带

e# - 公开最后编辑文件

bd# - 关闭未标明的缓冲

在这方面,我做了些什么。 因此,在排除所有缓冲器和上述多数解决办法之后,我要保持我的好奇立场,只是无视这一事实。 我还认为,重新确定指挥比打上指挥更佳,因此,我在这里使用<条码>和代号;b来排除所有的缓冲,并跳回我的原 cur。

noremap <leader>bd :%bd|e#|bd#<cr>| "

<代码>%bd = 删除所有缓冲器。

<代码>e# = 开放最后的缓冲,以供编辑(Which 是缓冲Im在工作)。

bd# to delete the [No Name] buffer that gets created when you use %bd.

两岸的管道相互接连。 页: 1

<代码>“ = 保持我方位。

<说明>::如评论意见所述,此封/windows不是缓冲区

使用

:on[ly][!]

以及

:h only

关闭所有开放的缓冲地带:

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

关闭所有开放的缓冲带,但目前的除外:

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

将这一功能添加到<条码>。

召集地图:

nmap <Leader>c :call CloseAllBuffersButCurrent()<CR>

因此,这是一个老的问题,但它帮助我为我的项目提出一些想法。 关闭所有缓冲地带,但现在使用的是,

map <leader>o :execute “%b >#”<CR>

:%bd then Ctrl-o

:%bd

Ctrl-o 跳回最后的缓冲地带,即你提到的“这一天”。

  • The answer with highest votes will reopen the buffer, it will lose the current line we are working on.
  • Close then reopen will induce a flush on screen
function! CloseOtherBuffer()
    let l:bufnr = bufnr()
    execute "only"
    for buffer in getbufinfo()
        if !buffer.listed
            continue
        endif
        if buffer.bufnr == l:bufnr
            continue
        else
            if buffer.changed
                echo buffer.name . " has changed, save first"
                continue
            endif
            let l:cmd = "bdelete " . buffer.bufnr
            execute l:cmd
        endif
    endfor
endfunction

let mapleader =  , 
nnoremap <leader>o :call CloseOtherBuffer()<CR>

此前的法典将在你到达目标缓冲和新闻时生效。 它将关闭除目前外的其他所有缓冲地带。

它将所有缓冲器全部放开,并关闭所有与目前缓冲号码不相同的缓冲号码。

我喜欢1,100bd (.suggested by juanruiz, 似乎为我工作。

我在地图上添加了一个<条码>空白!

nnoremap <leader>bd :1,100bd<CR>
nnoremap <leader>bdq :1,100bd<CR>:q!<CR>

这造成所有的缓冲,关闭了Vim,这是我所期待的。

页: 1 s comment:

command! Bonly silent execute "%bd|norm <C-O>"
  • The norm <C-O> jumps to the last position in the jump list, which means where the cursor was before the %bd.
  • I used silent instead of silent!. That way, if any open buffers are modified, Vim prints an error message so I know what happened. The modified buffers stay open in my tests.

nnoremap <leader>x :execute  %bdelete|edit #|normal `" |bdelete#<CR>
  • Close all buffers (side-effect creates new empty buffer)
  • Open last buffer
  • Jump to last edit position in buffer
  • Delete empty buffer




相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签