How I use bookmarks in RubyMine

RubyMine (and probably many other editors as well) have a nice feature called bookmarks. It lets you mark certain lines and easily navigate to them. I wanted to present you two scenarios in which I use the feature.

Editing big test/spec file

Let’s say I am in a quite long spec file. Quite long means between 200–2000 lines and multiple scenarios in it. I am editing/tweaking one of them and there is lot of code around. I want to focus on one test only. What do I do? I add a bookmark in the place I want to change. I used to use comments for that such as #MAKE_CHANGE_HERE. Nowadays, I just use bookmarks.

Bookmark in line 30 to help me remember to focus on this test.

I enjoy using RubyMine mostly because of its navigational features, which let me easily jump around code to find out something that I need. So let’s say I jump into order_shipped method (using Navigate/Declaration) to see what it does. Then I could jump further and further. When I find what I wanted to find I would use Navigate/Back to go back to where I was in a code a moment before (like back and forth in a browser).

Going back after navigating around

Obviously I don’t use the mouse but the keyboard shortcut. It depends on the platform so I am just showing where you can learn about it. After I go back I would land on the same screen I was before.

Same screen when I navigated back to it.

Normally I would be confused for a brief moment about what to look at. But the bookmark (and the highlighted line where cursor is right now) reminds me what I wanted to edit and that I am in fact in the right place.

Bigger refactorings

When I refactor a class or a method usually the search results are good enough for my navigating purposes. So let’s say I am not sure about the discard method, maybe I would like to change a few things around it, rename or change arguments.

I can use Find Usages and, from the panel with results, navigate to certain lines and introduces changes.

If you jump to the right place and the search results occupy too much space you can close the panel to edit more freely. Later, bring the panel back easily using Switcher to go back to those results and jump to another line you would like to change.

Use Switcher to re-open hidden search results

But sometimes the changes are bigger in scope and I want to put everything in my head (and IDE) before proceeding. I often need to see what’s the scope of the change I would like to introduce. How many places would I need to change to introduce a certain feature? So I go around some files and when I see something that I believe I would touch I add a bookmark as well.

Toggle bookmark. Use menu until you learn the shortcut.

So after visiting a couple files, and adding bookmarks, I can use the bookmarks navigator to go around them and actually introduce the change. Having everything limited to just a few places I spotted helps me focus exclusively on them.

Quickly navigating to your bookmarks.

That’s it. That’s how I use one or many bookmarks to help me focus on the particular part of the code I need to change. As you can see my workflow usually consists of two separate steps.

  1. Identify the scope of change and affected places.
  2. Introduce the actual change.

Do you use bookmarks in your editor as well? What’s your strategy for navigating and changing the code?

P.S. The code screenshots in this post come from our upcoming Rails workshop in Lviv, which focuses on learning new coding techniques for making your code more maintainable.