diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4ab78b9f8a..d8c46020bc 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1256,8 +1256,11 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags) buf = buf->b_next; } } else { + const bool help_only = (flags & DOBUF_SKIPHELP) != 0 && buf->b_help; + bp = NULL; - while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) { + while (count > 0 || (bp != buf && !unload + && !(help_only ? buf->b_help : buf->b_p_bl))) { // remember the buffer where we start, we come back there when all // buffers are unlisted. if (bp == NULL) { @@ -1265,12 +1268,13 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags) } buf = dir == FORWARD ? (buf->b_next != NULL ? buf->b_next : firstbuf) : (buf->b_prev != NULL ? buf->b_prev : lastbuf); + // Avoid non-help buffers if the starting point was a help buffer + // and vice-versa. // Don't count unlisted buffers. - // Avoid non-help buffers if the starting point was a non-help buffer and - // vice-versa. if (unload - || (buf->b_p_bl - && ((flags & DOBUF_SKIPHELP) == 0 || buf->b_help == bp->b_help))) { + || (help_only + ? buf->b_help + : (buf->b_p_bl && ((flags & DOBUF_SKIPHELP) == 0 || !buf->b_help)))) { count--; bp = NULL; // use this buffer as new starting point } diff --git a/test/old/testdir/test_buffer.vim b/test/old/testdir/test_buffer.vim index 2bdc709482..cf4d264066 100644 --- a/test/old/testdir/test_buffer.vim +++ b/test/old/testdir/test_buffer.vim @@ -169,6 +169,17 @@ func Test_bnext_bprev_help() b XHelp1 blast | call assert_equal(b4, bufnr()) + " Cycling through help buffers works even if they aren't listed. + b XHelp1 + setlocal nobuflisted + bnext | call assert_equal(b3, bufnr()) + bnext | call assert_equal(b1, bufnr()) + bprev | call assert_equal(b3, bufnr()) + setlocal nobuflisted + bprev | call assert_equal(b1, bufnr()) + bprev | call assert_equal(b3, bufnr()) + bnext | call assert_equal(b1, bufnr()) + %bwipe! endfunc