代码之家  ›  专栏  ›  技术社区  ›  Alex Mckay

Vim:在缓冲区中循环时忽略其他窗格中打开的缓冲区

  •  0
  • Alex Mckay  · 技术社区  · 3 年前

    假设有两个窗格垂直分割,多个缓冲区打开。我有 file-a.txt/buffer 1 .

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

    1 回复  |  直到 3 年前
        1
  •  2
  •   Jorengarenar    3 年前

    简单的解决方案是检查缓冲区是否在其他窗口中打开。如果是,那就执行 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 function again to go next one.
      endif
    endfunction
    nnoremap <leader>b :call Bnext()<CR>