vim-bbye
vim-bbye copied to clipboard
Doesn't support "set confirm"
Hi there.
Loving the plugin. Makes everything infinitely easier and better behaved. The only issue I have right now is that it doesn't support vim's "confirm" option which will prompt on closing an unsaved buffer instead of asking for an exclamation mark. It's extremely handy and would be vastly preferred to the current method(which requires a separate key mapping for force closing).
For anyone else coming across this, I have the same problem (on neovim), and resolved it by switching to https://github.com/famiu/bufdelete.nvim , which also provides Bdelete and prompts if needed.
It looks like the (add ! to override)
error is being thrown here: https://github.com/moll/vim-bbye/blob/25ef93ac5a87526111f43e5110675032dbcacf56/plugin/bbye.vim#L12
If you have set confirm
in your ~/.config/nvim/init.vim
you should be able to modify ~/.config/nvim/plugged/vim-bbye/plugin/bbye.vim
to only throw that if confirm is not enabled:
if getbufvar(buffer, "&modified") && empty(a:bang)
if !&confirm
let error = "E89: No write since last change for buffer "
return s:error(error . buffer . " (add ! to override)")
endif
endif
This got [Y]es
and (N)o
working for me, unfortunately (C)ancel
throws errors like:
Error detected while processing function <SNR>19_bdelete:
line 50:
E516: No buffers were deleted: bdelete 7
This doesn't respect the set confirm
in your config, but adding my own confirm logic into the plugin seems to work better in general. You can do that in the same section I mentioned above like this:
if getbufvar(buffer, "&modified") && empty(a:bang)
let confirm_result = confirm("Save changes?", "&Yes\n&No\n&Cancel", 3)
if confirm_result == 1
write
echo "Changes Saved"
elseif confirm_result == 2
edit!
echo "Changes Discarded"
else
echo "Resume Editing"
return
endif
endif