Reputation: 8081
I'm looking for a way to make handle the !
after a command like :wq!
. This is in order to make my own function for quitting and/or writing files. I tried this but of course, it didn't works :
command! -nargs=0 SQ :call <SID>SaveAndQuit(0, 0)
command! -nargs=0 SWQ :call <SID>SaveAndQuit(1, 0)
command! -nargs=0 SQ! :call <SID>SaveAndQuit(0, 1)
command! -nargs=0 SWQ! :call <SID>SaveAndQuit(1, 1)
with the function function! <SID>SaveAndQuit( write, force )
. Is there a way to handle the !
?
Upvotes: 3
Views: 462
Reputation: 195209
Yes, you should use the -bang
attribute, then pass it to your function, and handle the !
in your function.
:h bang
e.g.
command ... -bang XYZ call Function('foo', <bang>0)
your function:
func Function (argstr, bang)..
"here you check the a:bang to decide what should be done.
Upvotes: 4