<p>I use screen to persist my work session and connect to the same session from multiple machines. How can I setup SSH and screen such that the XDISPLAY variable <em>inside</em> my persistent screen session is always set to the machine I am currently connecting from?</p>

<p>ie. I start the screen session at work and use gvim, which uses the X server running on my work machine. Later, I connect to the same session from home and also want to use gvim. But this time, I want gvim to use the X server on my home machine. I realize I could manually update XDISPLAY every time I connect from a different machine but I'd rather have an automated system.</p>

<p>Bonus points if I can actually <em>move</em> gvim from my work machine to my home machine while it is running. I tried <a href="http://manpages.ubuntu.com/manpages/hardy/man1/xmove.html" rel="nofollow noreferrer">xmove</a> but could never get it to play nice.</p>

There is no "trivial" way to change environment variables in foreign processes.
A straightforward solution might be to persist your
```
XDISPLAY
```
into a file on login and use a
```
PROMPT_COMMAND
```
to read this file before printing the next prompt.
For moving X applications around look at something like
```
X11vnc
```
or
```
Xvnc
```
.