Call an exclamation mark after defining the command as: wq

I'm looking for a way to make a handle !

after a command like :wq!

. This is in order to make my own function to exit and / or write files. I tried this, but of course it didn't work:

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 function function! <SID>SaveAndQuit( write, force )

. Is there a way to deal with !

?

+3


source to share


1 answer


Yes, you have to use the attribute -bang

, then pass it to your function and process it !

in your function.

:h bang

      

eg.



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.

      

+4


source







All Articles