Setting up Sublime Text Editor for Ruby on Rails
In this post I’ll go over how I set up Sublime Text Editor for Ruby on Rails development.
Sublime Text Editor is a popular proprietary text editor that runs on Windows, Linux and Mac OS. It’s highly customizeable, with many user-developed plugins that tweak various parts of the interface.
The full program can be evaluated for free indefinitely. It is paid software, so in evaluation mode you’ll receive a prompt asking if you’d like to purchase a license after every few file saves ($80 USD as of September 2017).
Step 1: Download Sublime Text Editor 3.
Follow the download instructions on https://www.sublimetext.com/3 and install.
Update (2017-09-17): As of September 2017, Sublime provides official repositories for apt, pacman, yum, dnf, and zypper, so Linux users can get updates through their package manager of choice after adding sublime-text to their source list as per their install instructions.
Step 2: Install Package Control Manager.
Follow the instructions on https://packagecontrol.io/installation. Package Control Manager can be used to list, enable/disable, install/uninstall Sublime Text Editor plugins.
Step 3: Install any Sublime Text Editor plugins.
Once you have Package Control Manager installed, you can open “Preferences/Package Control” to access the package manager interface.
Enter “Install Package” to get a list of all available plugins.
I currently use the following plugins. Links are provided for interest only, you can install the plugins within Sublime Text Editor using the package manager.
- GitGutter: https://github.com/jisaacks/GitGutter
- Adds color-coded icons to the left of changed lines to indicate uncommitted changes.
- Added lines are indicated using a green “+” icon, removed lines with a red arrow, and modified lines with a yellow square.
- SublimeLinter: http://www.sublimelinter.com/en/latest
- Base for language-specific extensions which verify syntax and code style.
- SublimeLinter-ruby: https://github.com/SublimeLinter/SublimeLinter-ruby
- Checks against syntax and code style guidelines for the Ruby programming language.
- SublimeLinter-rubocop: https://github.com/SublimeLinter/SublimeLinter-rubocop
- Adds more advanced static code analysis to the Ruby linter.
- Prerequisite: run “gem install rubocop” to install the backend code analysis tool.
Step 4: Add global key-bindings under “Preferences/Key Bindings - User”.
You can see “Preferences/Key Bindings - Default” for examples.
I like to set a key binding for reindenting files.
Step 5: Add global settings under “Preferences/Settings - User”.
You can add any settings you want to apply across Sublime Text Editor to this file. (https://www.sublimetext.com/docs/3/settings.html).
Step 6: Add project-specific settings.
If this is a new project, you can create a project-specific settings file by going to “Project/Save Project As…” and saving a file as project_name.sublime-project.
For my current project I’m using 2-space indentation, so I have the following settings in my sublime-project file:
See https://www.sublimetext.com/docs/3/projects.html for more on Sublime Text Editor projects.
Note: It can be a good idea to check .sublime-project files into version control so everyone has the same settings, and ignore other Sublime config files.
Step 7: (Debian LXDE) Set up a keyboard shortcut for starting Sublime Text Editor.
This is strictly optional, but in Linux I like to have keybindings for starting terminals and development environments.
Using Debian LXDE, I added the following keybinding to ~/.config/openbox/lxde-rc.xml. Keybindings can be added within the <keyboard>…</keyboard> object.
This keybinding starts Sublime Text Editor whenever the user types “Ctrl+Alt+s”. You can use any other key combination you like.
Helpful resources:
- Sublime Text Editor 3 documentation: https://www.sublimetext.com/docs/3/
- OpenBox key bindings documentation for Linux: http://openbox.org/wiki/Help:Actions