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


当前回答

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

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

其他回答

注意:正如注释中提到的,这会关闭窗口而不是缓冲区。

通过使用

:on[ly][!]

and

:h only
nnoremap <leader>x :execute '%bdelete\|edit #\|normal `"'\|bdelete#<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

关闭所有打开的缓冲区:

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,这正是我最想要的。