vim-bbye icon indicating copy to clipboard operation
vim-bbye copied to clipboard

Doesn't support "set confirm"

Open rsheasby opened this issue 6 years ago • 3 comments

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).

rsheasby avatar Feb 15 '19 12:02 rsheasby

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.

gibfahn avatar Dec 30 '23 14:12 gibfahn

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

jimafisk avatar May 31 '24 17:05 jimafisk

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

jimafisk avatar May 31 '24 17:05 jimafisk