tpope / vim-vinegar

vinegar.vim: Combine with netrw to create a delicious salad dressing
https://www.vim.org/scripts/script.php?script_id=5671
2.24k stars 88 forks source link

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

Open kogakure opened 10 years ago

kogakure commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

kejadlen commented 10 years ago

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 commented 10 years ago

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

jrhorn424 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

: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 commented 10 years ago

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

jrhorn424 commented 10 years ago

@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 commented 10 years ago

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

autocmd FileType netrw setl bufhidden=delete
jgallen23 commented 10 years ago

@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 commented 10 years ago

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

jgallen23 commented 10 years ago

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 commented 10 years ago

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

justinmk commented 10 years ago

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

jgallen23 commented 9 years ago

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.

hkjels commented 9 years ago

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

jgallen23 commented 9 years ago

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

dnr commented 9 years ago

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

jgallen23 commented 9 years ago

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

ashwin commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

try :set confirm or maybe :set hidden

errinlarsen commented 8 years ago

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

gn0rt0n commented 8 years ago

I am still getting this bug as well

bullfight commented 8 years ago

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 commented 8 years ago

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

trevordmiller commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

blkwtkns commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Any idea what broke this?

slashfoo commented 7 years ago

@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 commented 7 years ago

@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 commented 6 years ago

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
jrean commented 5 years ago

Up. I'm another victim.

BlakeWilliams commented 5 years ago

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 commented 5 years ago

@BlakeWilliams Thanks! That works perfectly.

JakeElder commented 4 years ago

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 commented 4 years ago

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)