otrebla
otrebla

Reputation: 245

How to reformat code on save in RubyMine?

Is there a way to automatically reformat my code when I Save All (cmd+s) on Mac RubyMine?

I tried to bind the shortcut CMD + S to both Save All and Reformat Code but that didn't do the trick.

Thank you

Upvotes: 4

Views: 1524

Answers (3)

Indigo
Indigo

Reputation: 2997

You can now do this with the latest RubyMine. Go to preferences -> Tools -> Actions on Save.

enter image description here

enter image description here

Upvotes: 3

nambatee
nambatee

Reputation: 1568

Try recording a macro that involves reformatting your code and assigning a new keyboard shortcut to it.

  1. First go to to Edit -> Macros -> Start Macro Recording. A small green box should appear at the bottom right-hand corner - Macro recording started...
  2. Go to Code -> Reformat Code.
  3. Go to File -> Save All.
  4. Go to Edit -> Macros -> Stop Macro Recording.
  5. Name your macro (e.g. reformat on save)
  6. Go to RubyMine -> Preferences -> Keymap and look for your macro (e.g. reformat on save) in the search box at the top right-hand corner.
  7. Right-click your macro and Add Keyboard Shortcut.
  8. Go with cmd + s or cntrl + s and override the existing one.
  9. Click Apply and OK.

Upvotes: 5

Dave Schweisguth
Dave Schweisguth

Reputation: 37627

There is not a way to reformat on save that I know of. However, you can tell RubyMine to reformat before committing by checking the appropriate checkbox in the Commit Changes dialog. Not that I would do that myself -- if someone misformatted a file and I then changed one line, I wouldn't want my commit to include all the reformatting.

Upvotes: 1

Related Questions