Monday, July 26, 2010

My top 10 Eclipse keyboard shortcuts

Keyboard shortcuts are time-savers. Surprisingly, not many people around me use them. Programming is much more fun when you can control most of the action via the keyboard. I introduce some of the shortcuts I use the most in Eclipse. I don't bother mentioning some very common ones, like Ctrl+S for saving, or the king of all, Ctrl+Space, for auto-completion. Here is my top 10 Eclipse keyboard shortcuts to beat the uninitiated.

Ctrl+. : Navigate to the next item. When there are errors in the source, this jumps to the next error. The uninitiated uses his mouse and clicks on the little red square, or clicks in the Problem view, or worse, PgUps/PgDowns to the error. Press Ctrl+. while he is still scrolling his way to the error.

Ctrl+1 : Quick Fix. This will bring a list of possible fixes for errors. For example, on a method which does not exist, it will show fixes like "Create method in...", "Rename method to...", etc... The uninitiated hovers over the error to display the quick fix, which is not so bad after all. But the Ctrl+. Ctrl+1 double combo leaves him way behind.

Ctrl+E : Quick Switch Editor. Open the editor drop down list. Very useful when you have many resources open. The uninitiated clicks on a tab. When there are too many tabs, he clicks on the "Show List" icon and looks for his tab in the list, without even typing the name of the tab, because he still has his hands scotched on the mouse.

Ctrl+Shift+G : Search for references in workspace. Use this on variables, methods, classes to quickly find out where they are used. This one always leaves the uninitiated on their butt :)

Ctrl+Shift+R : Open resource. When you get used to a project and want to quickly jump to a resource, like a properties file, this is very useful. The uninitiated browse through the Package Explorer or Navigator view to find it.

Ctrl+Shift+T : Open type. Like the previous shortcut, but for types. I use it a lot.

Alt+Shift+R : Rename and refactor. This allows to not only rename a variable, method, class, etc..., but also to refactor the places which use the entity being renamed. The uninitiated renames it by hand, and goes through all errors to fix it. I'm exaggerating, aren't I ? But, I'm curious to know how many uninitiated go to the Navigator view, right-click on a class, and choose "Rename..." to rename a class ?

Ctrl+O : Quick outline. In a class, this allows to quickly jump to a method. The uninitiated uses the Outline view, or worse, Ctrl+F (ouch). Ctrl+O is a knock out shortcut.

Ctrl+Shift+O : Organize imports. I always leave Eclipse manage imports. Especially for unused imports. Auto-completion also takes care of the imports most of the time. The uninitiated uses his mouse to do the same.

Ctrl+F8 : Select perspective. Press repeatedly to cycle through available perspectives. Again, the uninitiated uses his mouse.

That's it ! I don't think that you have to remember a lot of shortcuts to increase your productivity, but these surely help me increase it. Think about the actions you often do and make your own list !

4 comments:

  1. I use Ctrl-Alt-J Join lines a lot when cleaning up formatting

    ReplyDelete
  2. Great tut. I never knew about the Ctrl + . and Ctrl + 1. Now i don't need the mouse anymore :D

    ReplyDelete
  3. Ctrl+Shift+F is one of my favorite, it automatically formats you the opened class

    ReplyDelete
  4. ctrl+alt+c for comment
    ctrl+d for delete line

    ReplyDelete