Tramp in Spacemacs

TRAMP (Transparent Remove Access, Multiple Protocols) is a package for editing remote files from within emacs.

One of my most ‘wat’ moments using emacs is discovering the incredible tramp mode.

My previous workflow for ssh was open a shell, ssh to host, edit file or whatever close connection. A lot of times what a really want to do is just paste something which I have from an already open buffer into a remote file, or copy a line etc. It turns out this is really easy to do from emacs.

SPC f f will bring up the file find in Spacemacs

ssh emacs

Typing /ssh: will auto complete your hosts, if you haven’t added your public key to authorized_keyson the host machine you can use the user@<ip_or_hostname> syntax and spacemacs will prompt for the
 password when connecting.

You can continue to auto complete your way to the file you want to edit, 
/ssh:<hostname>:/path/to/file and emacs will open the file in a new buffer.

Opening a shell

If you rather get a open shell on the remote machine you can do cd /ssh:<hostname>:/path/to/dir from eshell and emacs will open a shell in the specified directory. Other commands such as lsworks equally well.

Using SPC f f within the eshell will give you the context of the remote host
so you can open remote files using find file.

cd with eshell

Editing as sudo

If you need to edit a file as sudo: SPC f f and use the /su:: or /sudo:: syntax, emacs will prompt for your sudo password, select a file, edit, save. Very convenient!

Docker & Vagrant

The docker.el package provides tramp integration, in spacemacs it’s just a matter adding the docker layer to your .spacemacs config.

This enables you to type /docker:/<container_id> which will use docker exec to run commands within the container.

The same goes for vagrant just use /vagrant:<vm_name>:/

Learn more

Tramp is very feature rich and I encourage you to check out the manual for more.