Using Emacs - 25 - Tramp

Today's video talks about using emacs Tramp mode.

Tramp mode allows you to edit remote files using your local emacs. I usually do this over ssh.

To edit a file on a machine www.cstuy.org I would first find-file using C-c C-f and then for the file name to open:

/ssh:www.cstuy.org:/home/zamansky/sc/testfile

this would open the file testfile in the absolute directory /home/zamansky/sc. If my username on the remote machine is different:

/ssh:username@www.cstuy.org:/home/zamansky/sc/testfile

And I can also work relative to my home directory:

/ssh:username@www.cstuy.org:sc/testfile

If I just hit enter after the machine name and : -

/ssh:username@www.cstuy.org:

I end up in a dired buffer on the remote machine.

Likewise if I run a shell or eshell in the tramp buffer, it will run the shell on the remote machine. In the video I showed how shell didn't work because locally, I'm configured to use zsh and I don't have zsh installed remotely. Eshell, however, worked fine.

Using tramp in this way gives us all of the power of our local emacs configuration to edit a file on a remote machine.

You can also use tramp to edit local files as root using sudo:

sudo::/tmp/sc/rootfile

Note the double colon.

Finally, you can do the double-whammy - remote root editing:

ssh::www.cstu.org|sudo:www.cstuy.org:/home/zamansky/sc/rootfile

If you use zsh and any of this freezes, just do a search on "zsh tramp" and the top couple of hits will tell you what to add to your configuration files to fix things.

Finally, I mentioned in the video that I don't use tramp all that much anymore. That's mostly because I don't do much remote editing anymore. I used it more when I was administering a number of machines at Stuyvesant.

I still use it periodically, but I also use sshfs, a Linux tool (which may be available for other operating systems) that allows me to mount a directory tree from a remote machine and use it on my local machine.

Comments

Comments powered by Disqus



Enter your email address:

Delivered by FeedBurner

Google Analytics Alternative