views:

598

answers:

2

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

+1  A: 

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.

dertyp
+2  A: 

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

rampion
hey 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?
Stafford Rootbeer
I'm not familiar with that status message from screen. Sorry.
rampion
Set 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.
Joseph Garvin