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.
The problem with Ctrl-Z
When you suspend a process with Ctrl-Z, the process gets a SIGTSTP
signal, and all execution will stop (i.e., no more CPU cycles), until a SIGCONT
signal comes along. You will not be able to send vim
any commands or input while it is suspended.
In other words, don't use Ctrl-Z.
Yet if you have vim
compiled with the clientserver
feature enabled, you can make use of the --servername
and --remote-*
options:
Use vim --remote
When starting your vim
session for the first time, use vim --servername VIM [filename ...]
(filename is optional if you want to start with a blank session).
Leave it running in your terminal. Now you can control it from any other terminal window, tab, machine, etc., via vim --remote
commands. To open a file (e.g., file.txt in a new tab of your existing vim
session:
vim --remote-tab file.txt
To use vim
's internal :tabfind
functionality (see :help find
for more information):
vim --remote-send ":tabfind filename.txt<CR>"
To use your system's find(1)
program instead, as you asked in your question:
vim --remote-tab `find $PWD -name build.xml`
Multiple sessions
You can also specify a different --servername
, which is useful if you want multiple vim sessions. In that case, you need to supply the --servername
argument every time:
vim --servername HAMBURGER # Start new session named "HAMBURGER"
vim --servername HAMBURGER --remote-tab `find $PWD -name BACON`
Of course you can roll this all into a shell script or two to save yourself some typing.
Best Answer
In either your .bashrc or .zshrc, depending whether you use bash or zsh respectively, export these two environment variables:
Adittionally, you might want to associate vim to the mimetype of text files:
Now you'll have to create a vim.desktop file in
/usr/share/applications
, which should execute the terminal emulator you want, opening vim.