Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
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.

Comments
  1. Chad Woolley says:

    Another great article, thanks. Some here that I didn’t use, I’ll have to work on it.

    I also feel that ctags isn’t (can’t be?) as good as RubyMine’s code-awareness, but I’ve never known enough about ctags (or how it can be enhanced/configured) to say this definitively.

    Maybe it’s time for an update of http://pivotallabs.com/the-great-ruby-ide-smackdown-of-09/ ? You sound like the person for the job ;)

    — Chad

  2. Sebastian says:

    option/alt + shift + control + Up/Down is like morning yoga. Great article.

  3. Jared Carroll says:

    @Chad – That’s a great post from a few years ago. I don’t know if I’m ready to update it just yet though. Thanks again for the feedback.

  4. Andrew Brown says:

    In the pivotal labs RubyMine keymap, navigate back/forward command-option-Left/Right seems to conflict with the tab navigation for a pane. Are you using a different keymap?

    I’ve used command-shift-delete to navigate back through code I’ve edited, but sometimes it’s not quite what I want.

  5. Jared Carroll says:

    @Andrew,

    I originally was referencing the Mac OS X keymap. This was linked from http://www.jetbrains.com/ruby/documentation/. Since the release of
    RubyMine 5.4 last week, this link now points to the Mac OS X 10.5+
    keymap. I’m assuming this is the keymap JetBrains wants OS X users to
    now use. I’ve updated this post to use the Mac OS X 10.5+ keymap.

    A few developers in the Boulder office have begun a new keymap. This
    keymap is based on the Mac OS X 10.5+ keymap, and then adds Pivotal keymap
    shortcuts, if the shortcut is not already taken. They started this keymap
    to make it easy to switch between RubyMine and IntelliJ, e.g., when
    switching between Ruby and Android development.

  6. Nima says:

    Thanks for the useful shortcuts, I recently moved from windows to mac and i really wanted to know the shortcuts that intellij uses on mac.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *