I am trying to figure out how to script vim to send a message to a gnu screen "window". i.e. I have a screen session open and in one window I have a vim session and in the other a scheme interpreter. When I save my vim session I would like it to restart the interpreter in the other window loading in the new environment. I can figure out everything other than how to have an "on save" hook in vim send a shell command to another "screen window" causing the script to terminate and restart. if I could figure out how to send commands I could kill the process and then start a new one - I just need to make sure it starts in the right "window".
2 Answers
Have vim issue shell commands, and use screen -X
to issue commands to screen. Some permutation of :at <other-window> stuff <restart-command>
. See man screen
's customization section for more commands.
For example, if I was in screen window 1, using vim, and I had an irb session in window 0, to restart the irb session, I would do
:!screen -X at 0 stuff exit^Mirb^M
(^M
entered via CTRL-V Enter).
-
1hey that is great! almost exactly what I was looking for - the only issue is that it sends the command I want to the other screen but then waits til I press enter (or after 10 seconds) to have it actually "paste" it into the screen? It says "command from {username}: {command}. Do you think there is a way to make screen just accept the command as soon as it receives it? Oct 3, 2009 at 18:25
-
-
2Set msgwait to 0 (C-a : msgwait 0 <ENTER>) and it will get rid of the delay. You can register it to set the msgwait, run the real command, then set it back. Jul 9, 2010 at 19:35
If it is sufficient for you to have the scheme interpreter run every so many seconds, you could just run watch /path/to/scheme/interpreter /path/to/scheme/file
in the second screen window. Adjusting the time intervals in which watch
runs commands can be adjusted using command line parameters. The watch
man page contains the details.