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

[RO] buffers of netrw don’t get closed #13

Open
kogakure opened this issue Jan 8, 2014 · 44 comments
Open

[RO] buffers of netrw don’t get closed #13

kogakure opened this issue Jan 8, 2014 · 44 comments

Comments

@kogakure
Copy link

kogakure commented Jan 8, 2014

I found a strange behavior in using vim-vinegar. After a while the buffers opened by "-" don’t get closed any more and stick around (so there might be a dozen buffers with netrw trees open). It’s not possible to close them at all. Not with :bd, :q or even :!bd, !q. The only way to exit vim is to kill it or close the tmux window.

I get this error repeated when trying to close such a buffer:

E37: No write since last change (add ! to override)
E162: No write since last change for buffer "app/views/foldername"

This may be a conflict with some other plugins, but deactivating some plugins which handle buffers like Ctrl-P didn’t help.

@justinmk
Copy link

justinmk commented Jan 8, 2014

Yep, this is one of the most maddening behaviors of netrw. I actually have a hack in my vimrc to kill these buffers, but I haven't settled on whether it causes any side effects in netrw:

https://github.com/justinmk/config/blob/59b064bb9433449d308b7b889922e2d1c77a30c5/.vimrc#L662

To be clear, netrw sometimes leaves its buffers marked as 'readonly' and 'modified'.

@edkolev
Copy link

edkolev commented Jan 8, 2014

This isn't related to vim-vinegar. I've seen this before installing it.

I've fixed it by removing these 3 lines from my vimrc https://github.com/edkolev/dots/blob/2ade8ec0d427d7d0b087379239f0d893276ec1f9/vimrc#L297-L299

Not sure which one of them was causing the misbahavior

@justinmk
Copy link

justinmk commented Jan 8, 2014

Well treeview (g:netrw_liststyle=3) has all kinds of problems, but I don't think it is the cause of this issue.

@kejadlen
Copy link

I get the same thing, but I found that I could use :bd with the buffer id to close the buffer as a workaround. Ideally, I'd be able to just :bd in the buffer to kill it, though.

@jgallen23
Copy link

this still happens to me a lot. anybody come up with a solid workaround?

@jrhorn424
Copy link

Only slightly better is if you have a buffer manager (I user buffergator) you can usually mark buffers for deletion from that popup window. I choose the buffer in the buffergator window, press d, and move on to the next one that needs deleting. Works similar to emacs in that regard.

@serebrov
Copy link
Contributor

serebrov commented Apr 4, 2014

This workaround seems to help:

function! QuitNetrw()
  for i in range(1, bufnr($))
    if buflisted(i)
      if getbufvar(i, '&filetype') == "netrw"
        silent exe 'bwipeout ' . i
      endif
    endif
  endfor
endfunction

autocmd MyAutoCmd VimLeavePre *  call QuitNetrw()

At least since I added this to vimrc I don't remember to have this problem.

@dnr
Copy link
Contributor

dnr commented Jun 9, 2014

:qa! works for me to quit vim when it gets into this state. I never had this problem with netrw alone, though, only when I started using vinegar.

@wedens
Copy link

wedens commented Jun 25, 2014

I'll be glad if someone provide working solution.. Those stuck netrw buffers is freaking me out :(

@jrhorn424
Copy link

@wedens I've been navigating away from open netrw buffers with <C-o> and closing them with my buffer manager. I use unite to manage buffers, but most buffer managers have d mapped to close the highlighted buffer in the management window. Otherwise, list the buffers with ls and then issue a bdelete $number where $number is the number of the buffer listed in ls output.

@tpope
Copy link
Owner

tpope commented Jun 25, 2014

There has to be a better way than these convolusions. What about

autocmd FileType netrw setl bufhidden=delete

@jgallen23
Copy link

@tpope that didn't work for me. I still get netrw buffers listed (ones with - at the end are netrw):

screen shot 2014-06-27 at 10 01 17 am

@tpope
Copy link
Owner

tpope commented Jun 27, 2014

Can you check and make sure 'bufhidden' is getting set? You can also try a value of wipe.

@jgallen23
Copy link

bufhidden doesn't appear to be set. Not sure if it's conflicting with other plugins. I know ctrlp tries to do something special with netrw

@hkjels
Copy link

hkjels commented Sep 19, 2014

On my box, netrw remains hidden to the native vim buffer-lists, but for some reason Unite buffer will display them. Really annoying.

@justinmk
Copy link

I recommend filebeagle https://github.com/justinmk/vim-dirvish if you don't use the remote features of netrw.

@jgallen23
Copy link

Thanks @justinmk going to give that a try because buffers are still not getting closed.

I dug a little deeper and when I manually open up netrw, the buffers don't show up, but if I use vinegar they do.

af added a commit to af/dotfiles that referenced this issue Nov 20, 2014
@hkjels
Copy link

hkjels commented Jan 20, 2015

This is very annoying. I've tried to find what causes this bug without any luck.

@jgallen23
Copy link

I just ended up just using netrw without vinegar because this bug was so annoying.

@dnr
Copy link
Contributor

dnr commented Jan 20, 2015

I switched to filebeagle also (https://github.com/jeetsukumaran/vim-filebeagle). It's just like netrw+vinegar, but faster and without this bug.

@jgallen23
Copy link

@dnr I tried filebeagle, but it didn't have a way to create directories or delete files, which is important to me

@ashwin
Copy link

ashwin commented Feb 2, 2015

Adding this to .vimrc did not work for me:

autocmd FileType netrw setl bufhidden=delete

However, this worked partially for me:

autocmd FileType netrw setl bufhidden=wipe

The first buffer used by NetRW would stick around. But all subsequent NetRW buffers get wiped by this command.

@Konfekt
Copy link
Contributor

Konfekt commented Feb 12, 2015

Both additions should fall flat because netrw resets &bufhidden in ~.vim/autoload/netrw.vim. See http://www.reddit.com/r/vim/comments/2vfb8o/ignore_certain_buffers_from_c6_jumps/coh6wo9

@zhanjh
Copy link

zhanjh commented Apr 1, 2015

try
:set confirm
or maybe
:set hidden

mdippery added a commit to mdippery/vimfiles that referenced this issue May 21, 2015
Vinegar has this annoying habit of leaving the file listing buffer open,
which pollutes Vim's buffer list. There is a debate as to whether it is
vinegar's or netrw's fault [1], but regardless, it's a problem that
still hasn't been fixed. filebeagle does not have this issue and
operates in nearly the same way as vinegar, so I'm going to start using
that instead.

  [1] tpope/vim-vinegar#13
@errinlarsen
Copy link

What ever happened to this? I still seem to have this bug happening.

@gn0rt0n
Copy link

gn0rt0n commented Mar 4, 2016

I am still getting this bug as well

@bullfight
Copy link

I encountered this most when attempting to close all my currently open buffers with something like
:bufdo bd however I just found that you can use :%bd instead and this works even with an open netrw buffer.

@urxvtcd
Copy link

urxvtcd commented May 26, 2016

for me it was treeview. removing g:netrw_liststyle=3 from my vimrc seems to work

@trevordmiller
Copy link

I'm having a similar problem; I made a video of the entire process:
https://youtu.be/GSEZteQWkW4

It doesn't seem to have anything to do with vinegar or how many buffers I have open; however, when I create a split window and open netrw, that window becomes "locked" in read-only ([RO]) mode. I don't have any netrw or vinegar settings in my .vimrc.

@tpope, sorry to pollute your plugin with this as I know it is a netrw problem and not a Vinegar problem - but any ideas how to fix this?

@ericbock
Copy link

I found that if I have set hidden in my .vimrc or if called before my first netrw - that I get these orphan netrw buffers. If I don't, I can open a file with vim-vinegar / netrw and then set hidden and things work as expected (no orphans).

@kiryph
Copy link
Contributor

kiryph commented Nov 2, 2016

I have posted a possible solution for orphan/stray netrw buffers in #66 and #74 regardless whether set hidden or set nohidden. Please tell me, if it helps.

@caneta
Copy link

caneta commented Feb 10, 2017

This thing is incredibly annoying...and using vim-startify I store in my sessions those pending netrw windows too!
Is there a way to kill these windows? :bd does nothing...

@polyzen
Copy link

polyzen commented Feb 20, 2017

Having hidden unset, as mentioned by @ericbock, roughs out the edges, but those buffers are still there. See :ls! and :Rex.

@blkwtkns
Copy link

blkwtkns commented Apr 2, 2017

I don't use Vinegar (as of yet), and I happened upon this issue on my own just using native netrw commands. I almost strictly use netrw feature ':Lex(plore)', and I just noticed yesterday that it has been adding these 'orphan' buffers to the window. the suggested augroup fix seems to stunt it to a one to one amount (so two if you happen to have multiple explorers open, which a completely different issue I'm suffering from using netrw/Lexplore), and just one orphan if all explorers are 'closed'. But now :Rex has been pretty usuable, I just get an error message "warning (netrw) win#1 not a former netrw window".

I thought this might be useful information here, it seems that many might think this is a Vinegar, but I think my experiences may indicate it's a bit deeper.

@slashfoo
Copy link

the workaround that has worked for me has been:

adding this to my .vimrc

" Remove 'set hidden'
set nohidden

And then setting set bufhidden=hide for all non 'netrw' buffers with something like the following:

augroup netrw_buf_hidden_fix
    autocmd!

    " Set all non-netrw buffers to bufhidden=hide
    autocmd BufWinEnter *
                \  if &ft != 'netrw'
                \|     set bufhidden=hide
                \| endif

augroup end

By doing this, you can do :bd or whatever other method for closing the netrw buffers.

@spacepluk
Copy link

Any idea what broke this?

@slashfoo
Copy link

@spacepluk, I think it has to do with netrw and how it handles the bufhidden and whatnot, as well as the settings it imposes on the buffers it creates and how it handles switching to other buffers. This is not a vim-vinegar issue, this is a netrw issue I think, as I've been able to reproduce the problem with no plugins whatsoever other than the ones that ship with vim.

@spacepluk
Copy link

@slashfoo I tried reverting find -iname "*netrw*" scripts to older versions all the way back to 2014 and I still got the same broken behavior (without any plugins). I think the problem is somewhere else, or maybe I missed some files.

@virus-found
Copy link

Bug very easily reproduced in vim 8.0.1386 on mac os x:
:set hidden
:Explore
hit enter on any file
:bd

:verbose set hidden?

nohidden
        Last set from /usr/local/Cellar/vim/HEAD-8e6a31d/share/vim/vim80/autoload/netrw.vim

smancill added a commit to smancill/vim-config that referenced this issue Mar 2, 2018
Add experimental workaround to remove netrw buffers from the buffer
list.

This happens when using vinegar to navigate the directory of the current
file: the netrw buffers may stick around unclosed [1], or the first
netrw buffer will be part of the list of buffers [2]. It is annoying to
navigate buffers with buffergator or ctrlp when there are several netrw
buffers listed along with the open files.

Try setting the bufhidden option to delete the netrw buffers, and use a
custom function to delete that first netrw buffer that is not removed
just by setting bufhidden.

[1] tpope/vim-vinegar#13
[2] tpope/vim-vinegar#74
smancill added a commit to smancill/vim-config that referenced this issue Mar 2, 2018
Add experimental workaround to remove netrw buffers from the buffer
list.

This happens when using vinegar to navigate the directory of the current
file: the netrw buffers may stick around unclosed [1], or the first
netrw buffer will be part of the list of buffers [2]. It is annoying to
navigate buffers with buffergator or ctrlp when there are several netrw
buffers listed along with the open files.

Try setting the bufhidden option to delete the netrw buffers, and use a
custom function to delete that first netrw buffer that is not removed
just by setting bufhidden.

[1] tpope/vim-vinegar#13
[2] tpope/vim-vinegar#74
@jrean
Copy link

jrean commented Dec 20, 2018

Up.
I'm another victim.

@BlakeWilliams
Copy link

Came across this issue in my search for finding out how to get netrw buffers to close themselves.

I had to set g:netrw_fastbrowse to 0 to resolve this. Hope that helps.

@sandrodz
Copy link

@BlakeWilliams Thanks! That works perfectly.

yangle added a commit to yangle/dotfiles that referenced this issue Jun 2, 2019
... and don't ever show the netrw buffer in the buffer list.
tpope/vim-vinegar#13
kejadlen added a commit to kejadlen/dotfiles that referenced this issue Dec 3, 2019
@JakeElder
Copy link

Came across this issue in my search for finding out how to get netrw buffers to close themselves.

I had to set g:netrw_fastbrowse to 0 to resolve this. Hope that helps.

This seems to have worked for me 🤞

@streof
Copy link

streof commented Sep 9, 2020

In my case I had to remove the following line

" Save whenever switching windows or leaving vim
au FocusLost,WinLeave * :silent! noautocmd w

which was conflicting with netrw when using the tree view (g:netrw_liststyle=3)

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

No branches or pull requests