keyboard labs mouse_free_development rubymine

Navigate Code, Not Text: How to Navigate Effectively in RubyMine

Terminal text editors often allow you to navigate in terms of basic text objects, such as, characters, words, or lines. For maximum speed, the commands for these simple navigations are usually available on home row keys; so you don’t have to use the arrow keys.

Unfortunately in RubyMine, performing these basic movements requires using the arrow keys. However, I saw this disadvantage as an opportunity to research alternative navigations. RubyMine may make simple movements tedious, but it adds many powerful code-based navigations. By being aware of programming constructs such as methods, and classes, RubyMine demonstrates the difference between IDEs and text editors. In this post, we’ll look at some of these unique navigation commands for OS X.

Navigating by Symbol

command + option/alt + O is for when you know what you’re looking for, but not where it is. This shortcut performs a fuzzy search of project symbols. It allows you to quickly find classes and methods.

find by symbol

Navigating by Method

When browsing an unfamiliar file, it’s common to want to move through it one method at a time. This allows you to quickly scan method signatures, and browse implementation. Use control + Up/Down to move forward and backward by method.

Navigating to a Specific Method

If you know the method you’re looking for, then navigating by method is too slow. Instead, use command + F12 to open a file structure dialog, then begin typing the method name to navigate to it.

navigate to a specific method

Navigating to a Declaration

Navigating directly to a type declaration is one of RubyMine’s best features. This is often available in terminal text editors via ctags. However, I’ve never been able to successfully configure ctags to work as powerful as RubyMine’s version.

Press command + B when your cursor is on a class/module object to open its declaration. If you don’t want to open the declaration, use command + Y to quickly view it in a separate window.

quick definition

Press command + B when on a variable to navigate to its declaration. Navigate to the declaration of the type of a variable with control + shift + B.

Navigating Class Hierarchies

If you’re interested in the subclasses of a particular class, press command + option/alt + B on a class object.

view implementation

Use command + U within a class declaration to navigate to its superclass. Within an overridden method, command + U will navigate to its superclass definition.

Navigating to Related Files

RubyMine’s awareness of Rails allows you to quickly move between models, views, helpers, controllers, and their tests. When editing, use control + command + Up to be presented with a menu of related files.

Navigating Tests

When test driving a Rails project, it’s great to be able to quickly switch between test and non-test code. Use command + shift + T to move between a file and its corresponding test file (and vice-versa). In a split tab layout, for example, a vertical split between test and non-test code, command + shift + T will move between the splits.

After running your tests, use command + option/alt + Up/Down to quickly navigate between failing tests.

Navigating Between Changes

Version control introduces an interesting way of navigating. In RubyMine, file changes are highlighted (in various colors) in the editor’s gutter. Use option/alt + shift + control + Up/Down to move between these changes.

navigate changes

Navigating Through Navigations

RubyMine even provides commands to navigate backward and forward through executed navigation commands. Use command + [/] to move through your navigation command history.

IDEs vs. Editors

A text editor doesn’t know what kind of text it’s editing. Code aware extensions are usually added on via plugins, distorting the editor’s basic purpose. An IDE, like RubyMine, with its powerful code-based navigations, really shows the advantages an IDE has over a basic text editor.

Edit: updated keyboard shortcuts from the Mac OS X keymap to the Mac OS X 10.5+ keymap.