Sunday, February 10, 2013

Sublime Text 3 Quick Install and Setup for Rails on Linux

Sublime Text 3 Beta is now open to non-registered users (27 June 2013).
Sublime Package Control for ST3 is currently in Alpha.

Install ST3

Download latest deb build from
Install (double click) then copy / paste your licence
If you have a conflict with ST2 then remove it (see below) or download the tarball

sudo apt-get remove --purge sublime-text-2
sudo apt-get autoremove

Install Package Control

cd /home/username/.config/sublime-text-3/Packages
git clone "Package Control"
cd "Package Control"
git checkout python3

Add some Basic User Settings (adjust according to your preferences)
Preferences > Settings - User
"color_scheme": "Packages/RailsCasts Colour Scheme/RailsCastsColorScheme.tmTheme",
"detect_indentation": false,
"font_face": "Consolas",
"font_size": 13,
"scroll_past_end": false,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": true

Use Package Control to install a Theme
Popular packages are: RailsCasts Colour Scheme, Theme - Soda, Solarized Color Scheme

Update your Preferences > Settings - User to swap
Use Package Control to install syntax highlighting
Haml, Sass, Less, Coffeescript select them as defaults for the corresponding filetypes (click on the current filetype at the bottom right of ST3 window).

ERB Insert and Toggle Commands

Add to User Keybinding File
  { "keys": ["ctrl+shift+."], "command": "erb" }

Run Tests in the console
Install RubyTest

You must run Sublime Text 3 from the command line (subl)

control shift t Run all tests in the file
control shift e Run last test

There are issues with Colour output and esc characters - you may prefer to use the linux terminal

Create a plugin to Open file in browser
Tools > New plugin...

Copy code below / paste / save as
import sublime, sublime_plugin
import webbrowser

class OpenBrowserCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      url = self.view.file_name()

Add to User Keybindings to Open file in new browserPreferences > Key Bindings - User

Copy code below / paste / save
  { "keys": ["ctrl+shift+b"], "command": "open_browser" }