Programmer productivity stems from the ability to easily and efficiently navigate, create and edit the code you need to work with. To this end, it’s incredibly important to pay attention to the efficiency of your own daily workflow. If you’re regularly repeating tedious tasks that have multiple steps, it’s important to take some time out to automate these issues.
This isn’t taught on a lot of computer science courses — it isn’t strictly computer science so that’s understandable — but it’s incredibly important for your efficiency, effectiveness and ability to remain a happy, motivated programmer. Too many tedious tasks cloud and distract from the real problems you’re trying to solve.
In this post I want to focus on the workflow-improving plugins I use with Sublime Text 2 to make my navigation around rails and ruby projects fast and efficient. I’m not going to focus on debugging, validating, snippets or the plethora of other aspects that are also important for good coding. Instead I’m going to focus specifically on how we navigate around our projects and have all the info we need at our fingertips as quickly as possible.
Automating your common navigation tasks
Sublime makes navigating to any file pretty easy with a quick tap of ⌘-T and a few characters from the filename. Although this is pretty efficient, it’s not always efficient enough when you’re doing it many times a day. Instead we can use the Sublime Rails Navigator plugin.
It helps you get around a rails project with fewer keystrokes than the standard fuzzy filename navigation. You can easily switch between a model and its controller, a controller and its tests, a view and its stylesheets, and more.
In the projects I work on, the
Gemfile in particular evolves at a fairly rapid rate: I often want to check what our version constraints are for a dependency, or I need to update a gem, add new dependencies, etc.
For this I wrote RailsSpecialFileNav to give me a single keyboard shortcut to jump to the Gemfile (or Rakefile) that’s in the nearest parent directory to your currently active view/file. Tapping the same shortcut a second time takes you immediately back to where you were editing.
Get to your project’s source of truth
To talk about code with team mates easily, it’s important to be able to quickly make references to the code in a way that everyone can view. GitHubinator enables you to jump from the editor to a file’s official github page, and maintains any line highlighting in the URL.
This makes it trivial to quickly select lines in a class, and with one keyboard-shortcut to have the URL for its official browsable github page. You can paste it into hipchat or an email to get instant feedback from the team; either to get help with a piece of code that’s causing trouble, or to show off a neat new hack.
Cracking open your dependencies
When obscure bugs strike, it’s often due to mis-aligned expectations about a gem: I make one assumption about how a library will probably work, the author made a different one.
But the code doesn’t lie: browsing a gem’s source on github can help tremendously, but unless your project is on a constant upgrade cycle, the latest code in a gem’s github repo is often not the same version that your application is running. Bundler’s
Gemfile.lock specifies which versions you’re using for every dependency in a project but it’s not very human-friendly.
For that, I was very excited to discover Sublime Gem Browser. It serves two key purposes: one lets you fuzzy search the gem names (and versions) that your project is using. Then by selecting a gem it opens a new window with the full source of the gem version that your application uses. This lets you then bring the full power of Sublime’s fuzzy file opening and fast search to find the method you’re curious about or having trouble with:
One quick note: I had trouble getting Sublime Gem Browser to work with my projects that use RVM gemsets: if you use a
.ruby-version and a
.ruby-gemset file in your project try installing my fork instead for now. I’ll update this post when I figure out what about my environment is stopping the main plugin working.
Hack your own workflow
Introspecting your day-to-day repetitive tasks and figuring out which of them can be automated is a great way to boost productivity. It’s hard but the best programmers do it and take pride in it.
A life-hack on that front is to follow the work of other programmers who are already aggressively pursuing that approach. Tim Pope is the most notorious vim plugin hacker in the world. At one point Conrad Irwin would release a brand new pry plugin almost every weekend. Anders Nøklestad is consistently turning out great enhancements to Sublime Text.
If you haven’t already, customize your Sublime Text by installing SublimeRailsNavigator, RailsSpecialFileNav, GitHubinator and SublimeGemBrowser (or my gemset fork) and then start building your own plugin.
Do you have favorite plugins for navigating your projects? Have you written any workflow hacks? Let me know in the comments below!
Follow @LeeMallabone to see future workflow hacks, front-end dev tips, tricks and more.