I have a started vim
. I suspended it (Ctrl+Z). So I was in terminal session and I would like to open some file with the same vim
session (new tab). I can open the file in new vim
session. Actually, path to file could be constructed. For example,
vim `find $PWD -name build.xml`
Is it possible to open this file inside the running vim session from hosting terminal session?
Best Answer
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 aSIGCONT
signal comes along. You will not be able to sendvim
any commands or input while it is suspended.In other words, don't use Ctrl-Z.
Yet if you have
vim
compiled with theclientserver
feature enabled, you can make use of the--servername
and--remote-*
options:Use
vim --remote
When starting your
vim
session for the first time, usevim --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 existingvim
session:To use
vim
's internal:tabfind
functionality (see:help find
for more information):To use your system's
find(1)
program instead, as you asked in your question: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:Of course you can roll this all into a shell script or two to save yourself some typing.