Solarian Programmer

My programming ramblings

Remote text editing with SublimeText and TextMate

Posted on August 16, 2014 by Sol

A common problem for most server administrators and web programmers is how to edit text files quickly and efficiently on the server. For the Emacs and Vim gurus this is not really a problem, they’ll just install some plugin and do their work. What about the other 90% of the world, the mere mortals, that don’t know how to use one of the above editors ?

Some people will use a ftp client, like FileZilla, edit their files locally, with their preferred text editor, and upload the result to the server. Others, will chose to edit directly from a ftp client using the default text editor of their main OS (which on Windows, the horror …, is Notepad or on OSX is TextEdit). The savvy user will set his ftp client to use a more approachable, and usable, text editor like SublimeText, NotePad++, gEdit etc … The problem with using a ftp client to locally edit some file is that it is slow and somehow uncomfortable, at least for me.

In the next part of this post, I will assume that you have administrator rights on your web server and that this server runs on a different machine than your main computer. Another implicit assumption is that you want to use a text editor like SublimeText 3, which runs on all major operating systems, or TextMate 2 which runs only on OSX.

If you are a SublimeText user you will need to install first the Package Control. Once this is installed go to ToolsCommand Palette and select Package Control: Install Package, this will present you with a search box where you can write rsub. Once you’ve found rsub press Enter, the plugin will be installed. You can follow the above steps no matter if your main OS is Windows, Linux or OSX.

For the TextMate user (OSX only), select PreferencesTerminal and check Accept rmate connections:

TextMate settings remote editing

Next, we need a ssh client, for Linux and OSX this is usually already installed.

If you are a Windows user, you can install a ssh client from http://git-scm.com/download/win. This will install more than ssh, you will also end up with Bash, Git and a few other Unix utilities. Double click the installer and press NextNext until you are on the Select Components screen, make sure you check Git Bash Here, like in the next image:

Git installer options

Finish the installation, you can safely accept the defaults for all the other options.

Next step is to log in on the server and install Ruby and the rmate gem. I assume your server is based on Ubuntu, or Debian. Open a Terminal (if your local OS is Linux or OSX), if you are on Windows right click on your Desktop and select Git Bash Here. Now, you can log in to your server through ssh:

1 	ssh your_user_name_on_the_server@your_server_ip_address

Once you are logged in, you can write:

1 	sudo apt-get install ruby
2 	sudo gem install rmate
3 	exit

If the above commands were successful, you are again on your local machine. You will need to redo the next step every time you want to connect to your server, and locally edit a file. Now, we need to create a connection between our local machine and the server. If you are on Linux or OSX write:

1 	sudo ssh -R 52698:localhost:52698 your_user_name_on_the_server_@your_server_ip_address

For Windows, you don’t need the sudo part from the above command:

1 	ssh -R 52698:localhost:52698 your_user_name_on_the_server_@your_server_ip_address

Start SublimeText or TextMate and write in the Terminal (you should be still logged in after the last command):

1 	rmate test.txt

This will create a file on your server named test.txt and open the file in your editor of choice.

If you want to edit an existing file, you follow the same procedure:

1 	rmate exisiting_file_name

Saving the file in your editor will automatically update the file on the server.


Show Comments