在命令定义后处理感叹号为:wq

时间:2014-10-22 13:32:38

标签: vim

我正在寻找一种在!之类的命令后处理:wq!的方法。这是为了使我自己的功能退出和/或写入文件。我尝试了这个,当然,它没有用:

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)

使用函数function! <SID>SaveAndQuit( write, force )。有没有办法处理!

1 个答案:

答案 0 :(得分:4)

是的,您应该使用-bang属性,然后将其传递给您的函数,并处理函数中的!

:h bang

e.g。

command ... -bang XYZ  call Function('foo', <bang>0)

你的职能:

func Function (argstr, bang)..
"here you check the a:bang to decide what should be done.