Skip to content
Advertisement

In Intellij, how do I toggle between camel case and underscore spaced?

At my company we have two different style guides for java vs sql. In java I have a field named historyOfPresentIllness and when i write the sql, I want to name it history_of_present_illness. Is there a keyboard shortcut to switch from one to the other when I have the phrase highlighted? Or perhaps a plugin that can do this?

While I’m asking, I may as well ask if there’s a way to turn historyOfPresentIllness to history-of-present-illness. That’s from java to clojure style.

Advertisement

Answer

Two plugins offer this feature:

I use a plugin called String Manipulation which does what you need (and more).

Select historyOfPresentIllness and press Alt / option+M to bring up the plugin menu, then press:

  • 5To snake_case (or to camelCase) which converts to history_of_present_illness
  • 6To hyphen-case (or to snake_case) which converts to history-of-present-illness

To make this easier, you could set up a shortcut at File | Settings | Keymap.


There also is the CamelCase plugin.

SHIFT+Alt / option+U toggles the selection between formats:

historyOfPresentIllness –> history_of_present_illness –> HISTORY_OF_PRESENT_ILLNESS –> HistoryOfPresentIllness –> historyOfPresentIllness

You can also undo your changes (now that a bug in the plugin got fixed).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement