moll / vim-bbye

Delete buffers and close files in Vim without closing your windows or messing up your layout. Like Bclose.vim, but rewritten and well maintained.
http://www.vim.org/scripts/script.php?script_id=4664
Other
648 stars 32 forks source link

Doesn't support "set confirm" #15

Open rsheasby opened 5 years ago

rsheasby commented 5 years ago

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

gibfahn commented 6 months ago

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.

jimafisk commented 1 month ago

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 commented 1 month ago

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