Terminal and Vim

terminalvim

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

Related Question