Is there an autocmd event for kill signals (for e.g. SIGTERM) ? As this answer indicates Vim can catch SigUSR1 event. My use case is to save session on SIGTERM before quitting.


There's no such thing like "kill signal". There are different signals application may receive from OS.

SIGKILL cannot be caught by any application. Never.

SIGUSR1 can be processed by auto-command (see :h SigUSR1 in Vim and :h Signal in Neovim).

SIGINT is caught and processed by Vim application. If it happens to run some script while SIGINT is being raised then that script can :catch /^Vim:Interrupt$/ inside "try"-block.

SIGHUP, SIGTERM and alike force Vim to quit.

  • It is possible to catch SIGTERM as shown by this example in python. Does Vim allow doing something similar? – tejasvi88 Feb 9 at 14:08
  • 1
    @tejasvi88 As I said, Vim simply quits upon SIGTERM. – Matt Feb 9 at 14:14

vim offers the autocmd VimLeavePre

:autocmd VimLeavePre * call CleanupStuff()

Although this is not technically specific to SIGTERM, it can be used in this sitaution. You can use the variable v:dying to distinguish normal exits from abnormal (e.g., with a signal).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.