I want to check file before quitinq vim with custom functions, everything seems fine with QuitPre autocommand except using ZZ to exit. In this case the output is missing.

Consider following function declaration and autocommand in file function.vim

au QuitPre * call CheckBeforeQuit()

function CheckBeforeQuit()
  echo 'Hello'
  echo 'World'
  call input('Press enter')

And now when I open file tmp with this command

vim tmp -u NONE -c 'source function.vim'

and then type :x, the output Hello\nWord along with prompt message is visible. If I use ZZ instead, the message from echo is missing. According to help ZZ is the same as :x.

Of course I could remap ZZ to :x and everything is fine now. But anyway I would like to know what is causing this difference and how I could deal with that in my function.

  • 2
    Interesting, from the source code, we can see that it's calling directly the :x normal command: github.com/vim/vim/blob/… It will require more investigation because AFAIK it shouldn't remove the messages. – nobe4 Jan 16 '17 at 17:27
  • I don't think it has anything to do with differences between ZZ and :x, but rather it's a difference between how normal and ex-mode commands show output. With ex-mode (command mode), you see the whole output. With normal command, you only see the last line (unless your mapping also enters command mode). – Thunderbeef Oct 9 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.