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.
Asked
Active
Viewed 360 times
2 Answers
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
-
It is possible to catch SIGTERM as shown by this example in python. Does Vim allow doing something similar? – tejasvi88 Feb 09 '21 at 14:08
-
1@tejasvi88 As I said, Vim simply quits upon SIGTERM. – Matt Feb 09 '21 at 14:14
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