Today I Learned

9 posts about #rubymine

Copy current file path relative to project root

I already knew about copying the current file path to the clipboard by using Shift+Cmd+C . The problem with this approach is that it copies the absolute path, for example, /Users/arturo/src/cool_project/lib/module/my_file.rb. This is not ideal if you are planning on sending this path to someone else or for some document you are writing.

A better option is to use RubyMine's Action Copy Reference which by default is bound to Shift+Alt+Cmd+C. This copies the current file path relative to the project, for example, lib/module/my_file.rb

To summarize:

Copy Paths Action

  • Default shortcut: Shift+Cmd+C
  • Example text to clipboard: /Users/arturo/src/cool_project/lib/module/my_file.rb

Copy Reference Action

  • Default shortcut: Shift+Alt+Cmd+C
  • Example text to clipboard: lib/module/my_file.rb

Thanks to Jordan N. for the tip!

Exclusion using File Masks

When using Find in Path.. functionality to find a word across multiple files, file masks can be used to match certain types of files. For example, using *.rb will only look through Ruby files. On the other hand, if you want to exclude Ruby files instead, you can add an ! at the front (i.e. !*.rb).

Here are other useful examples/combinations:

all files excluding spec tests: !*spec.rb

all Ruby files excluding spec tests: *.rb,!*spec.rb

Attach to Local Ruby Process with Debugger

RubyMine has a nice feature that allows you to debug a Rails app without restarting the server.

With the server running,

1) Run the Attach to Local Process.. action from RubyMine

2) RubyMine will show a list of Ruby processes running. Pick the one running your server

3) Wait for RubyMine to connect to the process

4) Add a break point in RubyMine

5) Execute the action on the web application that hits that breakpoint

6) Execution will stop on that line. Now you can use all the nice tools the RubyMine debugger gives you.

I'm really exited with this new feature and I hope you are too. You can read more about it in here

RubyMine Attaches to Local Ruby Process

RubyMine Highlight for Multi-cursor Drag-and-drop

To create a Multi-cursor in RubyMine with your mouse, hold Alt while dragging your mouse up/down. This is especially useful if you want to adjust tabbing or add some extra characters on consecutive lines.

RubyMine group search by Test and Production code

When I do code searches in RubyMine, I sometimes want to only see non-test code for various reasons, such as knowing how often a particular method is used in our code base to judge adoption level. Normally, I would have to select each directory and run a code search one at a time, or search all directories at once and carefully skip over all test code while scrolling through the list. In a Rails app, directories that contain non-test source code could include app/, domain/, lib/ and even more.

There is a better way! The RubyMine Search tab has a toggle that will let you group source code search by Production and Test code. All you have to do is press this toggle and voila!

In RubyMine, shift a line or a whole block of code

RubyMine has a key-mapping for grabbing lines of text in the editor, from cursor focus. If you have your cursor focused anywhere in a line of code you can shift it up or down with the following [default] key bindings:

CMD + SHIFT + Up Arrow || Down Arrow

Supercharge your grabbing
If you want to move an entire block of code without having to highlight the entire block, put your cursor on the definition of the statement and RubyMine will shift the entire block for you.

This can work on blocks defined by module; class; def; if; find more use cases and share because I definitely haven't uncovered them all yet!

Happy Shifting!

Fix Mac RubyMine Floating Window Bug


On RubyMine in Mac, I want to have my RubyMine IDE in one window but have the Run display in Floating Mode appear in my secondary monitor. The issue, though, is that after I have moved the Run display into my secondary monitor, lose focus to another window, then click back into the Run display, the will suddenly JUMP to the same window as my main RubyMine IDE.


The problem appears to be a conflict with a setting in Mac's Mission Control. You will need to deselect the Displays have separate spaces option in the Mission Control preferences screen, as described here.


Pinch to zoom in Mac RubyMine


I am presenting some source code during a meeting on RubyMine on my Mac machine. When I plug into the projector, my display resolution becomes quite high, so all text on the projector become very small. Using CMD + does not zoom in.


Instead, you will need to pinch the Mac's touchpad with two fingers to control the zoom. Pinch inwards for zoom-out and outwards for zoom-in. You will need to do this on every code tab you have open.

Thanks for the tip, Sean Kirby.

Quick switching from a class to spec

RubyMine will attempt to open the relevant spec file for a class you're working with when you use the keyboard shortcut CMD + SHIFT + T.