Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netrw creating empty hidden buffers when toggling Lexplore with 'set hidden' #1016

Closed
iovis opened this issue Aug 27, 2016 · 13 comments
Closed

Comments

@iovis
Copy link

iovis commented Aug 27, 2016

Netrw v161, vim 7.4.2235

When I use :Lexplore with set hidden on my vimrc, every time I use my mapping to toggle off the window, it creates an empty hidden buffer.

nnoremap <leader>k :Lexplore<cr>

Just press the mapping a few times to reproduce the issue. It happens in older versions of netrw too (I upgraded to see if there was a fix).

@grochmal
Copy link

It is wise to contact Dr. Chip directly. His email is at the top of the netrw.vim file (and the other files in the netrw package). Still, a hidden buffer named NetrwTreeLisitng is normal for netrw, is simply the buffer that you see on the left pane (if you are using g:netrw_liststyle=3 that is).

Yet, when contacting him you should provide and debug it a little:

  • Provide all your g:netrw* options (from vimrc)
  • Test whether set hidden has an effect (I believe it doesn't)
  • Give the output of :ls! showing the hidden buffer.

(Dr. Chip is pretty quick in fixing things, I just made a test with the newest netrw because of your post and noticed that he already fixed an issue I reported less than a month ago)

@iovis
Copy link
Author

iovis commented Aug 27, 2016

Thanks, I tried to find an issue tracker for netrw and couldn't find any. And then I saw some netrw issues opened here so I guessed it was worth a try. This was replicated with no netrw configurations and it's 100% the set hidden option. With it on it creates a lot of empty buffers and without it it creates none.

I'll contact him directly, thanks for taking the time to reply!

@iovis iovis closed this as completed Aug 17, 2017
@jototland
Copy link

The issue is still there in the latest version of netrw. After skimming the source code, I believe it's because :new is used instead of :split when Lexplore needs to split the window, which creates a new buffer every time. You can fix this yourself in autoload/netrw.vim: search for " new" (including quotes and left-side space). Replace with " split". I've sent Dr. Chip an email.

@iovis
Copy link
Author

iovis commented Feb 4, 2019

Hopefully he implements the fix.
Thanks!

@chadwtaylor
Copy link

+1 I'm having this issue too.

@bam80
Copy link

bam80 commented Feb 8, 2019

I've sent Dr. Chip an email.

@jototland
Please, let me know if you receive the reply.
I've already sent 2 emails to Dr. Chip, but have never get a response.
So I even don't know if he received them, and if so - if he ignore them or what..

@jototland
Copy link

I got a reply. He's looking into it.

@felschr
Copy link

felschr commented Jun 4, 2020

It looks like this hasn't been fixed yet?

@jototland
Copy link

True. I never got any further replies, and had kind of forgotten about it. But I've asked him again. Anyway, the source is there, so it's not that hard to fix oneself, but it shouldn't really be necessary.

@jototland
Copy link

I got a thoughtful reply. My hackish bugfix attempt was not accepted.

Sorry, somehow your original email got forgotten in the mists of my backlog.

I don't believe that switching from new to split is the right way to do
it. If you want a split, you should use :Hexplore or :Vexplore. That
said, I do see the unwanted build-up of hidden buffers with repeated
uses of :Lex. :Lexplore's netrw window is intended to be
always-present, so quitting and repeating isn't the intended use.
However, given that :Lexplore is supposed to be always-present, its
bufhidden option may be set to wipe, so repeatedly re-invoking :Lexplore
will no longer cause hidden buffer build-up. Thus extra effort to
mis-use :Lexplore is thus warranted; this mostly affects users working
with remote directories (ie. ftp, scp, etc) as they may need to re-enter
credentials to get a listing.

That's the end of the story, I guess. If you want NERDTree, you know where to find it.

@iovis
Copy link
Author

iovis commented Jun 8, 2020

Thanks for looking into this and the final update

@cecamp
Copy link
Collaborator

cecamp commented Jun 8, 2020

From your last comment that you added on, I was wondering if you understood that netrw will not create hidden buffers when :Lex is repeatedly run and quit. I just did it a different way than you had.

@david-lorenzo
Copy link

david-lorenzo commented Aug 24, 2022

I found this thread because I was looking for a solution to this exact problem. It was disappointing to see there was no configuration tweak to fix this.

I've just created a function that clean the unnamed and unchanged buffers (those left overs after hiding Lex) and I decided to share it with you just in case anyone is interested.

Create a .vim file to save the function (for example: ~/.vim/explorer.vim) and add the following code:

function s:CleanUselessBuffers()                                                   
    for buf in getbufinfo()                                                                                               
        if buf.name == "" && buf.changed == 0 && buf.loaded == 1                   
            :execute ':bdelete ' . buf.bufnr                                       
        endif                                                                      
    endfor                                                                         
endfunction                                                                 
                                                                                   
function s:ToggleLex()                                                             
    call s:CleanUselessBuffers()                                                   
                                                                                   
    " we iterate through the buffers again because some netrw buffers are          
    " skipped after we browsed to a different location and hence the name          
    " of the window changed (no longer '')                                         
    let flag = 0                                                                   
    for buf in getbufinfo()                                                        
        if (get(buf.variables, "current_syntax", "") == "netrwlist") && buf.changed == 0 && buf.loaded == 1
            :execute  ':bdelete ' . buf.bufnr                                      
            let flag = 1                                                           
        endif                                                                      
    endfor                                                                         
                                                                                   
    if !flag                                                                    
        :Lexplore                                                               
    endif                                                                       
endfunction                                                                                   
map <Plug>ToggleLex :call <SID>ToggleLex()<CR>

And in your ~/.vimrc add the following map (or the one that you prefer):

source ~/.vim/explorer.vim
nmap <leader>f <Plug>ToggleLex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants