Saturday, May 12, 2012

Sublime Text 2 Setup for Rails

NB: Please see this post for Sublime Text 2 installation

After installing Sublime Text 2 these are the settings I use and packages I install to assist with Ruby on Rails development. Use all or some of these to suit your own needs.

Remove the Minimap 

View > Hide Minimap

Install Package Manager

View > Show console

Copy code below / paste / enter


import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

 

Install Ruby / Rails related Packages 

Preferences > Package Control > Package Control:Install Package
  • ERB Insert and Toggle Commands 
  • Rails Related Files 
  • RubyTest 
  • Rspec 
  • Guard 
  • Haml 
  • Sass 
  • Coffeescript 

 

User Settings

Preferences > Settings - User

Copy code below / paste / save

{
"color_scheme": "Packages/Color Scheme - Default/railscasts.tmTheme",
"font_face": "Droid Sans Mono",
"font_size": 12,
"scroll_past_end": false,
"detect_indentation": false,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": true
}

 

Create a plugin to Open file in browser

Tools > New plugin...

Copy code below / paste / save as OpenBrowser.py

# OpenBrowser.py
import sublime, sublime_plugin
import webbrowser

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

 

Add Keybindings to Open file in new browser and to insert ERB

Tools > Command Palette > "User Key bindings"

Copy code below / paste / save

[
{ "keys": ["ctrl+shift+b"], "command": "open_browser" },
{ "keys": ["ctrl+shift+."], "command": "erb" }
]