Terminal and Vim
There is no way for vim
to know in advance that it's grandparent process (the terminal) is killed so it too, is normally killed as a result of killing the parent processes.
However, on most default setups vim
will create a .swp
file named after the current file being edited; for instance MyPrecious.java.swp
. This file should contain a snapshot of the file MyPrecious.java
just before the vim
process was killed. Unless you have set up vim
to specifically put these .swp
files in some other directory, they should reside in the same directory as the edited file and you can easily restore your editing work.
Note that some of these files starts with a dot .
so they are invisible unless you use ls -a
to list the files in a directory.
Looking at the problem from a different angle, screen
or tmux
will allow you to keep your shell going independently of your terminal. When you close the terminal you can open a new one and reconnect to the original shell. Vim will still be running.
vim
has no control over how your terminal's GUI handles WM_DELETE_WINDOW
. Instead, look for a setting in your terminal that controls how the terminal acts when asked to close when it has a shell with children.