我怎么能关闭所有缓冲区在Vim除了一个我目前正在编辑?
当前回答
:%bd then Ctrl-o
:%bd删除所有缓冲区
按Ctrl-o跳转回最后一个缓冲区,即您所引用的“This One”。
其他回答
关闭所有打开的缓冲区:
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
将此函数添加到.vimrc并使用以下方法调用:
方便的地图:
nmap <Leader>\c :call CloseAllBuffersButCurrent()<CR>
你可以从vim.org上使用这个脚本:
http://www.vim.org/scripts/script.php?script_id=1071
只要把它放到你的。vim/plugin目录下,然后使用:BufOnly命令关闭所有的缓冲区,但激活的缓冲区除外。您还可以在.vimrc中将它映射到您喜欢的其他地方。
来源Github(通过vim-scripts镜像):https://github.com/vim-scripts/BufOnly.vim/blob/master/plugin/BufOnly.vim
:%bd then Ctrl-o
:%bd删除所有缓冲区
按Ctrl-o跳转回最后一个缓冲区,即您所引用的“This One”。
如果你不关心当前的,更简单的做法是(不需要脚本):
1,100bd
我喜欢1100bd (juananruiz建议),这似乎对我有用。
我添加了一个退出!我的地图给我
nnoremap <leader>bd :1,100bd<CR>
nnoremap <leader>bdq :1,100bd<CR>:q!<CR>
这会杀死所有缓冲区并关闭Vim,这正是我最想要的。