Is there a way to quickly capitalize the variable name in Eclipse

Pressing Alt+Shift+R gives you all the power to refactor your variable name to your liking. AFAIK, there is no tool or shortcut that does just the capitalizing.


What I find useful is column select using Alt+Shift+A and select a column of letters. Then use Ctrl+Shift+Y or Ctrl+Shift+X to lower case or uppercase letters.

This works for eclipse on windows.


There are a number of problems:

  • fooBar -> FooBar and vice-versa are unlikely to occur unless someone has been ignoring the Java style guidelines. (I rarely encounter such code, and when I do my initial reaction is to write off the code as beyond salvage.)

  • fooBar -> FOO_BAR and vice-versa are plausible, but pretty unusual.

  • foobar -> fooBar is also plausible, but it is problematic. It would entail Eclipse figuring out where the intended word boundaries are in a sequence of characters, and that is hard to get right.

If you look at these, they are all either unlikely to be needed much, or too hard to do properly. Hence, it doesn't surprise me that they are not supported by the standard Eclipse codebase.


Windows

After you press Alt+Shift+R as mentioned by kostja, you can select the text you want to change, then

  • Ctrl+Shift+Y for lowercase, or
  • Ctrl+Shift+X for uppercase.

Mac OS

  • Cmd+Shift+Y lowercase
  • Cmd+Shift+X uppercase

There is no intelligence in this. It just blindly changes the case on the selected characters.

note: This tip comes from eclipse help. If you need to find it, click Help, Search, then type "uppercase". You'll find a page with lots of shortcuts.

Tags:

Eclipse