I open a terminal then I open Vim. Then I work on my source code, but unfortunately I click on the close button of the terminal title bar and my work is lost. Is it possible to configure Vim such that it will tell me when I am trying to close the terminal without saving my work?
Thanks!
Best Answer
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 instanceMyPrecious.java.swp
. This file should contain a snapshot of the fileMyPrecious.java
just before thevim
process was killed. Unless you have set upvim
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 usels -a
to list the files in a directory.