justinmk / vim-dirvish

Directory viewer for Vim :zap:
Other
1.18k stars 64 forks source link

"E37: Buffer would be deleted" from startify #221

Open nickspoons opened 2 years ago

nickspoons commented 2 years ago

The latest commit 7e41cd7628d9844b4e66b45104f3abc326aa1a00 causes the E37: Buffer would be deleted error to be displayed when using - or :Dirvish from a vim-startify window.

Of course there is a simple workaround to open vim with vim . instead of just vim followed by -, but that won't help when opening startify manually from a vim session etc.

I'm not sure what the best solution is, whether some plugin/buffer types should be whitelisted, or whether the latest commit should have applied more specifically to git commits, or if a user-defined buffer variable should be introduced to bypass the error, e.g. au FileType startify let b:dirvish_allow_close = 1

justinmk commented 2 years ago

what does startify set 'bufhidden' to?

nickspoons commented 2 years ago

bufhidden=wipe

justinmk commented 2 years ago

I suppose [count]- could force it, so 1- would skip the warning.

nickspoons commented 2 years ago

Ah ... I thought of a problem with this solution regarding startify specifically: startify by default presents a list of up to 10 recent files, and maps the numbers 0-9 to open those files. Meaning that 1- from startify still requires some custom mappings.

nickspoons commented 2 years ago

I'm going to resolve this in my config with this mapping:

nnoremap <silent> - :bwipe <Bar> Dirvish<CR>

I don't know whether it's something you want to follow up here, or whether it's more of a startify issue, or just an unusual edge case for users to work around. Feel free to close.

justinmk commented 2 years ago

Let's see how common this is. The condition added in https://github.com/justinmk/vim-dirvish/commit/7e41cd7628d9844b4e66b45104f3abc326aa1a00 was somewhat hopeful.

blkwtkns commented 2 years ago

I just updated my dirvish, it's been awhile, but I'm encountering this as well when trying to navigate files with "-" to move up a directory. Is there anymore info about this? I tried out what @nickspoons suggested but that's not working for me.

justinmk commented 2 years ago

but I'm encountering this as well when trying to navigate files with "-" to move up a directory.

which files...? It certainly shouldn't happen for normal files.

I tried out what @nickspoons suggested but that's not working for me.

Because the mapping there was buffer-local. I've updated the comment, try again.

blkwtkns commented 2 years ago

@justinmk I just tried the updated comment, unfortunately it's still happening. This is happening while navigating through JS files. If I'm in a file, when I press - it opens the directory explorer, but pressing that key again does nothing for me. And then if I press enter on a target file, I get the dirvish: E37: Buffer would be deleted error.

justinmk commented 2 years ago

@blkwtkns well, what does :verbose set bufhidden? report in these buffers? Sounds like you have a plugin or configuration issue, has nothing to do with dirvish.

If you actually want 'bufhidden' behavior for all of your buffers, just set 'hidden' ...

blkwtkns commented 2 years ago

So the output of :verbose set bufhidden? should be hidden?

blkwtkns commented 2 years ago

I figured some workaround in my configs, I had the following setup, and just commenting the bufhidden=wipe line out makes things work again...which seems strange based on what's been discussed here. But it works!

  aug DirvishGroup
    au!
    au FileType dirvish setlocal relativenumber
    " au FileType dirvish setlocal bufhidden=wipe
    au FileType dirvish nnoremap <buffer><silent> v   yy<c-w>p:vs <c-r>=fnameescape(getreg('"',1,1)[0])<cr><cr>
    au FileType dirvish nnoremap <buffer><silent> h   yy<c-w>p:sp <c-r>=fnameescape(getreg('"',1,1)[0])<cr><cr>
    au FileType dirvish nnoremap <buffer> Q <C-w>q
    au BufEnter * call NormalizeWidths()
  aug END
  " command! -nargs=? -complete=dir Vexplore leftabove vsplit | vertical resize 25 | silent Dirvish <args>
  " nnoremap - :Vexplore<CR>
  command! -nargs=? -complete=dir Vexplore leftabove vsplit | silent Dirvish <args>

With this, output for :verbose set bufhidden? is just bufhidden=

justinmk commented 2 years ago

So the output of :verbose set bufhidden? should be hidden?

No. :set hidden. In general 'bufhidden' shouldn't be set at all, that is the purpose of this warning.

au FileType dirvish setlocal bufhidden=wipe

Why do you want this? Dirvish depends on Vim to remember the cursor position for visited Dirvish buffers, and other state. Wiping the buffer will break those Dirvish features.

mxngls commented 2 weeks ago

Why do you want this? Dirvish depends on Vim to remember the cursor position for visited Dirvish buffers, and other state. Wiping the buffer will break those Dirvish features.

My rationale behind wiping the Buffer on BufLeave or BufWinLeave is, that I do not want Dirvish buffers to be part of my jumplist in order to prevent unnecessary buffers to appear (i.e. the Dirvish buffer) when switching between buffers with <C-O> or <C-I>.