0

Ok so this question is vaguely related to one of my previous questions:

I want Vim to be able to save and close similarly to Photoshop in regards to buffers?

Basically the solution I found (or gets really close to what I want), is a plugin called BufOnly which basically closes all buffers that have not been modified. So when I have a lot of buffers open and I want to close, I just run this, and then just care of everything that I haven't already. It works well.

But I'm greedy. I want this to execute automatically when I need it to. Basically I would like it so that if I run qa, if qa runs into -->

E73: No write since list change (add ! to override)

Then I want to run

:BufOnly<CR>:bd <cr>

Is there a way to do that?

Community
  • 1
  • 1
Rey
  • 3,639
  • 5
  • 33
  • 40

1 Answers1

1

you can write a function with vim's try-catch mechanism. example:

 function! Funk()
    try
        execute "qa"
        let yes = 1
    catch /^Vim\%((\a\+)\)\=:E37/   
            execute "BufOnly"
            execute "bd"
    endtry
endfunction

this will catch the error :E37 and do the command you want. I don't have that plugin installed, I therefore didn't test with BufOnly. I tested with "h gg", it shows the help page of gg

to call the command, type :call Funk(), of course you could create mapping for that function call.

Kent
  • 189,393
  • 32
  • 233
  • 301