Vim: ignore buffers open in other panes when cycling through buffers

Viewed 65

Let's say I have two panes split vertically with multiple buffers open. I have file-a.txt/buffer 1 open in the left pane and my cursor is focused on the right pane. In the right pane I want to cycle through the remaining open buffers without going through file-a.txt/buffer 1.

That is, I want to ignore buffers open in other panes when cycling through buffers in another pane. Is this possible?

Thanks.

1 Answers

Simple solution is to check if buffer is opened in other window. If is, then just execute bnext again.

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>
Related