Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Last active March 11, 2021 13:31
Show Gist options
  • Save explodecomputer/d1ea9e8f6c81731e6883 to your computer and use it in GitHub Desktop.
Save explodecomputer/d1ea9e8f6c81731e6883 to your computer and use it in GitHub Desktop.
Instructions for Sublime Text 3

Setting up Sublime Text 3 for Mac

This guide shows some of the nice features of Sublime Text 3 (ST3):

https://scotch.io/bar-talk/the-complete-visual-guide-to-sublime-text-3-getting-started-and-keyboard-shortcuts

1. Download

Get it from here:

http://www.sublimetext.com/3

2. Setup Package Manager

Go here and follow the instructions. Or see the link above for a video showing how to do it.

https://packagecontrol.io/installation

3. Command line shortcut

In order to be able to open local files from within Terminal run:

sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

It will ask you for your root password. This is probably the same as your local user login.

Now you can open a local file in the terminal like this:

cd /path/to/dir
subl script.R

and it will open up in ST3.

4. Install the SendText plugin

This plugin will allow you to automatically copy and paste a line or selected text in your script to be executed in the Terminal by pressing cmd+enter.

To install:

  1. In ST3 press cmd+shift+p to bring up the command pallette.
  2. Type install packages and select the option called "Package Control: Install Package"
  3. It will load the available repositories and come up with a new window. Search for "SendText" and press enter.
  4. It will install and you are done.

Now if you are in a script try it out:

  1. Open up an R script in
  2. Open up Terminal and type R to get a command line R prompt
  3. In ST3 press ctrl+enter on a line or selection of text and it should automatically copy it across to the last Terminal window you had selected, and then execute that line.

This works for any type of file in ST3 and onto any Terminal window (e.g. you can step through bash scripts or python scripts interactively).

5. Opening remote files from BlueCrystal 3

You are going to create a tunnel on a chosen port every time you open up an ssh connection between your local machine and BlueCrystal 3 (BC3). This will allow you to open, edit and save files on BC3 using your local ST3 text editor.

First you need to choose a port. The following ones are taken so don't use them:

52799
53699
54747

For the tutorial I will just use port number 55555.

On your local computer

  1. Install the rsub and the PackageResourceViewer plugins (i.e. using the same method used to install the SendText plugin).

  2. You need to edit the rsub default preferences. To do this you will use the PackageResourceViewer.

    1. Open the command pallette (cmd+shift+p)
    2. Navigate to "PackageResourceViewer: Open Resource" > "rsub" > "rsub.sublime-settings"
    3. This will open a new file called rsub.sublime-settings. Change the value for "port" to the port number you have chosen.
    4. Save and close
  3. Open (or create) the file ~/.ssh/config and add the following lines:

     Host bluecrystalp3.acrc.bris.ac.uk
       ForwardAgent yes
       RemoteForward 55555 127.0.0.1:55555
    

On BC3

  1. SSH into BC3

  2. If necessary create a folder in your home directory called bin.

     mkdir -p ~/bin
    
  3. Download this script and save it to ~/bin/subl.

  4. Edit the port number on line 40 of the script to the port number that you have chosen.

  5. Change the permissions to make it into an executable

     chmod 755 ~/bin/subl
    

Now exit from BC3, restart ST3. Log back into BC3 and type

subl test.R

and it should open up a new file in ST3 called test.R. If you edit and save the file you will see that you have created the file on BC3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment