Tip #309: close vim you left open remotely
tip karma |
Rating 21/12, Viewed by 925
|
created: |
|
August 12, 2002 22:27 |
|
complexity: |
|
intermediate |
author: |
|
noah |
|
as of Vim: |
|
6.0 |
Vim 6 has this cool client-server protocol. I use it all the time to edit a file in an existing gvim, like so
$ gvim --remote [filename]
Today I left myself logged in at the console at work, and when I got home I realized I had left vim running with files unsaved. I think I even left it in insert mode. I wanted to edit these files at home. So I ssh'd to the machine and started playing with the --remote commands.
:help was a bit cryptic
--remote-send {keys} Send {keys} to server and exit.
After a lot of failed attempts, I finally succeeded in getting the remote vim to save its buffers and quit.
$ DISPLAY=:0 vim --servername GVIM --remote-send '<ESC>:wqa<CR>'
A couple of notable things. Then environment variable DISPLAY has to be the display of the remote vim, and you have to be able to open that display. The client-server stuff is done through X.
The <CR> is important. This part eluded me for a long time. The {keys} are just like keys you would press if you were editing at the console, and you have to press enter, or vim won't do anything.
Check your .swp files to make sure vim really closed the files it was editing. Vim provides little feedback as to the success or failure of what you're trying to do remotely. Nonetheless, it's clearly a useful feature to have available.
<<Move through wrapped lines. |
showing ascii value of the current character in decimal, hex, and octal >>
Additional Notes
|