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.
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).
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.
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.
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.
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.
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.
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.
- Identify the scope of change and affected places.
- 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.