Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reformat code on save in RubyMine?

Tags:

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

like image 681
otrebla Avatar asked Mar 19 '23 13:03

otrebla


1 Answers

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.
like image 162
nambatee Avatar answered May 12 '23 00:05

nambatee