Some Simple Tramp Tricks

One of the great and mostly underappreciated features of Emacs is the Tramp system that lets you seamlessly edit files on a remote computer. There are, of course, situations where Tramp is not the right answer—working with large files on remote servers connected over a slow or buggy connection, for example—but most of the time it’s exactly what you need to deal with remote files.

If you’re a Vim user, the typical answer is to just install Vim on the remote machine and SSH into it when you need to edit a file. That works pretty well especially if you don’t have much in your Vim configuration file. With Emacs and Tramp, you don’t have to install anything on the remote and your full Emacs system with all your configurations and tweaks are available because you’re working on your local machine. When you’re finished and save the file, it’s synced back to the remote machine just as if you’d been working on it instead of your local machine.

Will Schenk has a short post of some of the typical Tramp use cases. That includes editing a file on the remote machine even if you need to edit it as root. If you connect to a directory instead of a file, you get a Dired listing and can interact with it in the usual way even though all the files it lists are remote. You can even start a shell on the remote host right from Emacs using Meta+x shell in the normal way.

One of the most useful Tramp tricks is working on a remote machine that’s behind a gateway. Tramp has a mechanism that let’s you connect to the gateway machine and then to the target machine. That’s really handy especially if you’re trying to make a quick fix to one of your work machines from home. It’s a whole lot easier than having to go into work.

Finally, Schenk discusses connecting to a Docker image and shows a bit of Elisp to make it easy. You may or may not need that capability but it’s nice to know it’s available.

If you edit files on remote machines and you’re not using Tramp, you’re working too hard. It’s easy to get started: just try it on remote files for a while and after you get comfortable, you can try some of the more complicated tricks. Schenk’s post provides a nice go-by for some of the easier tasks but be sure to check out the documentation for the full story.

This entry was posted in General and tagged . Bookmark the permalink.