首页 > 解决方案 > Vim:在缓冲区循环时忽略在其他窗格中打开的缓冲区

问题描述

假设我有两个窗格垂直拆分并打开了多个缓冲区。我file-a.txt/buffer 1在左窗格中打开,我的光标集中在右窗格上。在右窗格中,我想在剩余的打开缓冲区中循环而不通过file-a.txt/buffer 1.

也就是说,我想在另一个窗格中循环浏览缓冲区时忽略在其他窗格中打开的缓冲区。这可能吗?

谢谢。

标签: vimneovim

解决方案


简单的解决方案是检查缓冲区是否在其他窗口中打开。如果是,则bnext再次执行。

function! Bnext() abort
  bnext                                " Go to next buffer.
  if len(win_findbuf(bufnr('%'))) > 1  " If buffer opened in more than one window,
    call Bnext()                       "  then call func again to go to next one.
  endif
endfunction
nnoremap <leader>b :call Bnext()<CR>

推荐阅读