The easy way to do this is, as sean and Kent suggest, to have vim
drive it.
However, if you only "mostly" work in vim, that may not be appropriate.
The only other alternative is to write code that uses your platform's filesystem watch APIs, or, if worst comes to worst, periodically polls the file, and runs it on each update. Then just run that code under your screen
or tmux
(presumably with vim
in another screen
window).
Since I don't know your platform, I'll write a stupid polling implementation to show the idea—just remember that in real life, you'd be much better off with a tool like inotifywatch
/fswatch
/etc.:
import os
import subprocess
import sys
import time
scripts = sys.argv[1:]
mtimes = {script: os.stat(script).st_mtime for script in scripts}
while True:
for script in scripts:
mtime = os.stat(script).st_mtime
if mtime != mtimes[script]:
subprocess.call([script], shell=True)
mtimes[script] = mtime
time.sleep(250)
Now, you can do this:
$ screen
$ python watch.py myscript.py
$ ^AS^A<Tab>^A^C
$ vim myscript.py