我怎么能关闭所有缓冲区在Vim除了一个我目前正在编辑?


当前回答

试试这个

bufdo bd

Bufdo为所有缓冲区运行命令

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

其他回答

关闭所有打开的缓冲区:

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>

我喜欢1100bd (juananruiz建议),这似乎对我有用。

我添加了一个退出!我的地图给我

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

这会杀死所有缓冲区并关闭Vim,这正是我最想要的。

这是一个老问题,但它帮助我为我的项目获得了一些想法。为了关闭除当前使用的缓冲区外的所有缓冲区,请使用;

map <leader>o:execute "%bd\|e#"<CR>

nnoremap <leader>x :execute '%bdelete\|edit #\|normal `"'\|bdelete#<CR>

关闭所有缓冲区(副作用创建新的空缓冲区) 打开最后一个缓冲区 跳转到缓冲区中的最后编辑位置 删除空缓冲区

试试这个

bufdo bd

Bufdo为所有缓冲区运行命令

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