Search code examples
vimnetrw

Is there a workaround for Vim's Netrw :bprev bug?


Vim's Netrw file explorer has the following bug: Running the command :e. will open Netrw, but after Netrw closes there is a latent buffer in Vim's buffer list which cannot be traversed with command :bprev. (:bnext works fine.)

This bug is discussed in the following places:

https://www.bountysource.com/issues/45921122-previous-doesn-t-work-with-e-buffer

https://groups.google.com/forum/#!topic/vim_use/zzeQItJQNZI

To replicate this bug, start Vim and run the following commands:

:ls!
:edit ./file1.txt | ls!
:edit ./file2.txt | ls!
:e. #(choose file3.txt in Netrw)
:edit ./file4.txt | ls!
:ls!

At this point, you will see buffers for the files you have opened as well as some buffers with paths, and a buffer with [No Name]. Try to navigate these buffers with

:bnext | ls!
:bprev | ls!

You will find that :bnext successfully loops over the buffers, but :bprev hangs on the Netrw buffer. Is there a workaround for this bug so that buffer navigation with :bnext and :bprev still works?

Edit 2021-11-28: Better explanations available here:

https://github.com/ap/vim-buftabline/issues/31

https://github.com/ap/vim-buftabline/issues/25


Solution

  • I've discovered through experimentation that :bprev will resume functioning if I delete the path buffer just prior to the [No Name] buffer. However, this is burdensome.

    Instead, I have started using :Explore to open Netrw. This does not create the latent buffer which trips up :bprev, but I am still able to browse my local directory tree and open files for editing.