0

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.

tejasvi88
  • 470
  • 2
  • 10

2 Answers2

1

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.

Matt
  • 20,685
  • 1
  • 11
  • 24
1

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).

Mass
  • 14,080
  • 1
  • 22
  • 47