Emacs & Vim remote editing under Cygwin

This article I want to dedicate to tricks for world famous text editors like Emacs and Vim. Sometimes there is a problem to edit a text file on a remote server. In this short article I’ll show you how.

To complicate the problem, we will do this under Windows and Cygwin.

We’ll use the ssh protocol to access the remote server. I won’t describe the process here how to do it on Cygwin. You should have already working ssh connection to your remote server. First, consider the editor Emacs. Emacs has the TRAMP mode. The TRAMP (Transparent Remote Access, Multiple Protocols) is a package for editing remote files. Whereas the others use FTP to connect to remote host and to transfer the files, the TRAMP uses a remote shell connection (rlogin, telnet, ssh). It can transfer files using rcp or a similar program, or it can encode the file contents (using uuencode or base64) and transfer them right through the shell connection.

OK, fire up the Emacs and press C-x C-f, then input such command to connect to your server you plan to edit:

Find file: /sshx:serverName|sudo:serverName:/var/www

This command use sshx which is important to use in Cygwin cause other ways will give you error. The sudo command allow you to edit the text file as root on remote host: serverName. In current example, the file is located on remote WEB server. You will get the files list just after you enter your remote user password. Check out your ssh configuration file.

The Vim can use the scp for the same task. You can call Vim by:

$ vim scp://user@serverName//absolute/path/to/document

This command is suitable for absolute remote path to file. The other way for relative path is:

$ vim scp://user@serverName/relative/path/to/document

Look on the slash. From Vim itself you can call the command by:

:e scp://user@serverName//absolute/path/to/remote/file

That’s all for today.

Welcome to leave the comment below and Thanks for your time…

comments powered by Disqus