Effective Eclipse_ Shortcut Keys _ Eclipse Zone

8
Login Join DZone 48 0 Ads by DZone Home Submitted by Tomas Kramar on Fri, 2008/02/15 - 5:35am Tags: Eclipse You should try to keep your hands on keyboard. The less you touch the mouse, the more code you can write. I am trying to keep the mouse laying still and control the IDE completely using keyboard. What do you think is faster: pressing ALT + C or right clicking the project, selecting Team -> Commit? It is said, that if a function does not have a key binding, it is useless. Below you will find a set of essential keyboard shortcuts that I love. These shortcuts are set up by default, they should all work. CTRL + D Delete row. Try it! You no more need to grab the mouse and select the line, no more Home, Shift + End, Delete. Quick and clean. ALT + Up/Down Arrow Move the row (or the entire selection) up or down. Very useful when rearranging code. You can even select more rows and move them all. Notice, that it will be always correctly indented. ALT + Left/Right Arrow Move to the last location you edited. Imagine you just created a class Foo, and now you are working on a class Boo. Now, if you need to look at the Foo class, just press Alt+Left Arrow. Alt+Right Arrow brings you back to Boo. CTRL+SHIFT+O Organize imports. What happens when you first use a class you have not yet imported? You will see an error. But when you press this magical combination, all your missing classes will be imported, and the unused imports will vanish. CTRL+1 Probably the most useful one. It activates the quick fix. Imagine you create a class, which implements some interface. You will get an error, because the inherited methods are not yet implemented. While you are on line where the error occurs, press this combination to activate the quick fix. Now, select the "Add unimplemented methods" option. You can use the quick fix at every error you ever receive. Quick fix comes handy in other situations too. My favorite is the "Split variable declaration". Sometimes I need to broaden the scope of a variable. I activate the quick fix, split declaration, and use alt + arrow to put it where it belongs. You can find even more usages: Convert local variable to field, rename in file, Inline local variable.. Community for Eclipse users and developers First Name: Tomas Last Name: Kramar Zone MVP Posts: 6 Joined: 08/12/2007 View full user profile About the author Spotlight Features Solr + Hadoop = Big Data Love Bixo Labs uses Hadoop to crunch its data and then serves it up in Solr, which is used as a key-value store. Will the Mobile Wars Become a 3-Horse Race? There are early signs that Microsoft's WP7 platform might become a third contender in this clash between mobile titans. Getting Started With Drupal in WebMatrix Get your feet wet with Drupal through WebMatrix, a new and powerful tool for web development on Windows. Popular at DZone How to develop modular server applications using OSGi Key Bindings in RAP Avoiding ALM ADD Setting Up Arquillian to Run in Eclipse Coding HTML5 Pages Using Eclipse Find Bar for Eclipse Video Tutorial: Android Application Development - BroadcastReceivers See more popular at DZone Subscribe to the RSS feed Home Microzones Zones Library Refcardz Links ITQuestions Snippets Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key 1 of 8 4/28/2011 5:16 PM

Transcript of Effective Eclipse_ Shortcut Keys _ Eclipse Zone

Page 1: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

LoginJoin DZone

480

Ads by DZone

Home

Submitted by Tomas Kramar on Fri, 2008/02/15 - 5:35am

Tags: Eclipse

You should try to keep your hands on keyboard. The less you touch the mouse, themore code you can write. I am trying to keep the mouse laying still and control the IDE completely using keyboard. What doyou think is faster: pressing ALT + C or right clicking the project, selecting Team -> Commit?

It is said, that if a function does not have a key binding, it is useless. Below you will find a set of essential keyboard shortcutsthat I love. These shortcuts are set up by default, they should all work.

CTRL + D

Delete row. Try it! You no more need to grab the mouse and select the line, no more Home, Shift + End, Delete. Quick andclean.

ALT + Up/Down Arrow

Move the row (or the entire selection) up or down. Very useful when rearranging code. You can even select more rows andmove them all. Notice, that it will be always correctly indented.

ALT + Left/Right Arrow

Move to the last location you edited. Imagine you just created a class Foo, and now you are working on a class Boo. Now, ifyou need to look at the Foo class, just press Alt+Left Arrow. Alt+Right Arrow brings you back to Boo.

CTRL+SHIFT+O

Organize imports. What happens when you first use a class you have not yet imported? You will see an error. But when youpress this magical combination, all your missing classes will be imported, and the unused imports will vanish.

CTRL+1

Probably the most useful one. It activates the quick fix. Imagine you create a class, which implements some interface. Youwill get an error, because the inherited methods are not yet implemented. While you are on line where the error occurs,press this combination to activate the quick fix. Now, select the "Add unimplemented methods" option. You can use the quickfix at every error you ever receive.

Quick fix comes handy in other situations too. My favorite is the "Split variable declaration". Sometimes I need to broaden thescope of a variable. I activate the quick fix, split declaration, and use alt + arrow to put it where it belongs. You can find evenmore usages: Convert local variable to field, rename in file, Inline local variable..

Community for Eclipse users and developers

First Name: TomasLast Name: KramarZone MVPPosts: 6Joined: 08/12/2007View full user profile

About the author

Spotlight FeaturesSolr + Hadoop = Big DataLoveBixo Labs uses Hadoop to crunch itsdata and then serves it up in Solr,which is used as a key-value store.

Will the Mobile Wars Becomea 3-Horse Race?There are early signs that Microsoft'sWP7 platform might become a thirdcontender in this clash between mobiletitans.

Getting Started With Drupal inWebMatrixGet your feet wet with Drupal throughWebMatrix, a new and powerful tool forweb development on Windows.

Popular at DZoneHow to develop modular server applications usingOSGi

Key Bindings in RAP

Avoiding ALM ADD

Setting Up Arquillian to Run in Eclipse

Coding HTML5 Pages Using Eclipse

Find Bar for Eclipse

Video Tutorial: Android Application Development -BroadcastReceivers

See more popular at DZone

Subscribe to the RSS feed

Home Microzones Zones Library Refcardz Links ITQuestions Snippets

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

1 of 8 4/28/2011 5:16 PM

Page 2: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

You could use the "Split variable declaration" on the bar variable, and then move it with Alt+Arrows above the try block..

Or you could use the "Add unimplemented methods" fix here.

The best thing you can do if you see an error is to use the quick fix.

CTRL+SHIFT+T

Open Type. Imagine, that you need to have a look at the Foo class. But, where is the Foo class? Is it in the Boo project andin the foo.bar package? Or somewhere else? With this shortcut, you don't need to know. Just press it, type Foo and you arein.

CTRL+E

Shows you a list of all open editors.

CTRL+F6

Use to move between open editors. This is an slower alternative to Ctrl + E. Comes handy in a situation when you want toperiodically switch between two editors, something, what is nearly impossible with Ctrl+E as it sorts entries quite randomly.Or you might just use Alt+Arrows..

CTRL+F7

Move between views. When in editor, press Ctrl+F7 to switch to the Package Explorer, or hold Ctrl and press F7 multipletimes to switch to other views.

CTRL+F8

Move between perspectives. The same as previous.

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

2 of 8 4/28/2011 5:16 PM

Page 3: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

CTRL + F11

Runs the application. What gets launched depends on your settings. It will either launch the last launched class (mypreffered way) or it will launch currently selected resource (the default way). If you want to change its behavior read theprevious post.

CTL + N

Open new type wizard. This is not very quick because you have to select the wizard type (weather you want to create newclass, jsp, xml or something else) in the next step. Much faster way would be if you could just hit the shortcut and invoke theparticular wizard. It is possible, just keep reading..

CTRL + M

Maximize or umaximize current tab.

CTRL + I

Corrects indentation.

CTRL + SHIFT + F

Formats code. You can make a beautiful looking code out of a mess with this. It requires a bit of setup, but it is well worth it.You can find its settings under Window->Preferences->Java->Code style->Formatter

CTRL + J

Incremental search. Similar to the search in firefox. It shows you results as you type. Don't be surprised, if you hit thiscombination, nothing happens - at the first glance. Just start typing and eclipse will move your cursor to the first ocurence.

CTRL + SHIFT + L

Shows you a list of your currently defined shortcut keys.

I don't like your shortcutsSuch is life nowadays. Remember, you can always change those bindings to match your preferences. OpenWindows->Preferences->General->Keys. Now you can use the filter to find your shortcut and change its binding.The real fun begins when you cannot find the command you are looking for. The key here, is to have the "Include unboundscommands" checkbox checked. It will show you all commands, even those, which have no keys bound.

While you are here, I recommend to add the following bindings:

CTRL+SHIFT+G

Bind this to "Generate getters and setters". This is a "must have".

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

3 of 8 4/28/2011 5:16 PM

Page 4: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

ALT+C

Bind this to SVN/CVS "Commit".

ALT+U

Bind this to SVN/CVS "Update".

Now, type "new" (without quotes) in the filter text. You should see a list of all new type wizards. Choose the most frequentlyused and assign them a shortcut. For example, the most used wizard for me is the new class wizard. Thus I assigned it theCTRL+SHIFT+N keys.

Let me demonstrate a quick way to create new class now.

Hit CTRL + SHIFT + N (or the combination you assigned in the previous step). This should bring up new class wizard. Typein the name and press ALT+E. You can now select a class which will be a superclass for the newly created class. Hit ALT+Aand select all implemented interfaces . Now hit ALT+F and your class will be generated. Eclipse will also provide the defaultimplementation for all abstract and interface methods you inherited.

Did you notice the weird underscores everywhere in the dialog? They give you a hint about the shortcut key. Hit ALT and theunderlined letter to press the button, check the checkbox or get focus for a textfield.

Did you notice the underscores?

I think that using shortcut keys is the fastest way to productivity and if not, then at least your wrists will say you a silentthanks. Now, don't wait, go on and assign keys to the features you use most.

One final tip from Andriy:

The problem is that there are so many keyboard shortcuts. I used to keep a printout with all the shortcuts Iwanted to use. Finally I wrote an Eclipse plugin MouseFeed, which reminds the keyboard shortcuts for theactions called with mouse. You can even tell it to enforce some shortcuts - the action will run only if called with akeyboard shortcut.

So if you are struggling with yourself, if you want to use shortcuts, but always subconsciously touch the mouse, install theplugin and let it enforce the shortcuts - the mouse will be useless and you will be forced to use keyboard.

What shortcuts do you use?

ReferencesReference: Effective Eclipse: II. Shortcut keys

Your rating:

Average: 4.5 (6 votes)

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

4 of 8 4/28/2011 5:16 PM

Page 5: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

Tomas Kramar lives in Slovakia, where he works for a company developing software for a major localtelecommunication provider. He is also a student at the Slovak University of Technology. Tomas is a DZoneMVB and is not an employee of DZone and has posted 6 posts at DZone. You can read more from them attheir website.

Login or register to post comments 217516 reads Printer-friendly version

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Mark Haniford replied on Fri, 2008/02/15 - 7:48am

Nice

Login or register to post comments

Cole Markham replied on Fri, 2008/02/15 - 10:15am

Very good overview of the most useful shortcuts. I really like the new class shortcut, I find myselfwanting that all the time, and I always forget that almost everything in Eclipse can have a key bindingeven if it doesn't already.

One thing I noticed is that you map CTRL+SHIFT+G to "Generate getters and setters". That's a greatshortcut, and I am about to set a key binding for it. But CTRL+SHIFT+G is mapped to "References->InWorkspace" which I use all the time. Place your cursor on a class, variable or method and fire theaction. This will show in the Search view all references of that item throughout your workspace. Veryuseful when you are trying to understand code.

A few more that I use religiously:

CTRL+ALT+H Open Call Heirarchy. Find out where that method is used.

F4 Open Type Heirarchy. See the subclasses and/or superclasses. This one can be tricky sometimes.If there is a class under the cursor it will open that class's heirarchy, if not it will use the class thatcontains the cursor (including inner classes).

F3 Open Declaration. Jump to the declaration of the variable, method or class. It will try to find the mostspecific declaration it can for methods, but depending on your code you might end up in an Interfacewhich is probably not what you want. Then just press F4 to get the type heirarchy and find theimplementation you are looking for.

ALT+SHIFT+R Refactor->Rename. Works in the editor and in the package explorer. If you haven'tlearned the power of refactoring, do so now. Think of this one as a super-smart Find-Replace. The new3.3 feature of inline rename is awesome.

ALT+SHIFT+V Refactor->Move. Again, works in both the edtor and package explorer. Move themethod or field to another class.

ALT+SHIFT+M Extract to method. Break up that monolithic code, takes the selection and trys to makeit into a method. Will optionally find duplicate code blocks and use the new method there as well. Itmight take a few trys to get this to work the way you want. Just try it, rearrange thee code a little and tryagain.

Login or register to post comments

David Karr replied on Fri, 2008/02/15 - 11:19am

Two things:

On "Ctrl-N" to create a new object, it is annoying that you then have to select the appropriate wizard,but after you press Ctrl-N, there's another shortcut that helps here. You simply start typing the type ofobject you want to create, like "class", and it narrows the list to the relevant items, then you pressEnter.

The next point is a question: What is "Split variable declaration"? I can tell from its name what it does,but I can't find a function in Eclipse that does this.

Login or register to post comments

Vijay Aravamudhan replied on Fri, 2008/02/15 - 11:30am

Nice compilation. Another complimentary tool for power eclipse users would be the MouseFeed plugin:http://www.mousefeed.com/

The plugin and the list above should be used in a complimentary fashion - since I dont think all the

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

5 of 8 4/28/2011 5:16 PM

Page 6: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

ones mentioned above show up in the plugin.

DISCLAIMER: I am in no way associated with the developer(s) of the plugin - just another user of thesame.

Login or register to post comments

Jeremy Weiskotten replied on Fri, 2008/02/15 - 2:51pm

Along with Ctrl+1, Ctrl+Space is one of my favorites. Start typing something, and hit Ctrl+Space andchances are that Eclipse has a hint about what you're doing. For example, type "for" and hit Ctrl+Spaceto generate a for loop (you can choose from the various types of iteration).

Login or register to post comments

Tomas Kramar replied on Fri, 2008/02/15 - 5:55pm

David,

I don't think that the "Split variable declaration" function can be accessed via menus. It is part of a quickfix feature - more on it later..

Just to make it clear:

when the "Split variable declaration" is applied on

Integer count = new Integer(22);

the result is

Integer count;count = new Integer(22);

Login or register to post comments

in response to: dk52519

David Karr replied on Fri, 2008/02/15 - 8:36pm

Hmm, is "Split variable declaration" only available in 3.4? I'm on 3.3.1.1, and I'm not seeing it.

Login or register to post comments

Cole Markham replied on Sat, 2008/02/16 - 4:51am

It's been around for a while, not sure how long, but I'm using it in 3.3. It's in the Quick-fix menu likeTomas mentioned, press CTRL+1 while the cursor is on the variable name to access it.

There is also the inverse, "Join Variable Declaration" perform the inverse. The variable must not havean assignment for it to be available. Something like this will not work:

Integer count = null;count = new Integer(23);

Be careful if there is something else in between though. Here's an example:

Integer count;if(someBoolValue){ count = Integer.valueOf(18);}count = new Integer(23);

will convert to this:

Integer count = Integer.valueOf(18);if(someBoolValue){}count = new Integer(23);

That is almost certainly not what was intended. Actually, that seems like a bug. I'll go check out bugzillaand file a report if it's not there.

EDIT: I found this bug which describes a similar issue with "Join variable declaration" and was markedas WONTFIX. The reasoning is that the tool is intended to be simple and useful, not necessarily alwaysproduce code that will compile (try running it from the variable inside the if statement, it pulls thedeclaration in there so subseqeunt accesses break). As such, I decided against filing another bug. Justbe careful what you are trying to do when you use this one.

in response to: dk52519

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

6 of 8 4/28/2011 5:16 PM

Page 7: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

Login or register to post comments

Tomas Kramar replied on Sat, 2008/02/16 - 5:42am

Maybe they are right, anyway, it is easy to press alt + arrow down to move it to the correct position.

Login or register to post comments

in response to: cmarkham

Raffaele Gambelli replied on Mon, 2008/02/18 - 9:28am

Hi Tomas, hi all!

And what do you think about the super new from Europa version CTRL + 3 shortcut?

It is an entry point for pratically everything inside Eclipse, fantstic in my opinion and very useful.

Best regards

Raffaele

Login or register to post comments

in response to: kremso

Tomas Kramar replied on Mon, 2008/02/18 - 3:17pm

Raffaele, this one is great! I didn't know about it, it is awesome.

Login or register to post comments

in response to: gamby

yqouyang replied on Tue, 2008/03/18 - 6:15am

Tomas and all you guys . thanks very much for tell me so much shortcuts I dont know.

Login or register to post comments

bhagwan tayade replied on Mon, 2009/01/19 - 3:53am

hi Thomas , its nice to visit u r website. i solved my some problems by using this eclipse.dzone.

Login or register to post comments

Stephane Eybert replied on Tue, 2009/03/03 - 3:47am

The thing that I miss most is being able to change focus to the currently hovered view, so as to be ableto scroll the hovered view with the mouse central scroll button.

As things are now I have to first click in the view to focus it. Spare my poor fragile hand please...

Login or register to post comments

jaga india replied on Thu, 2009/03/19 - 10:03am

hi to every one, first time log in to this site

Login or register to post comments

Muhammad Ali replied on Fri, 2009/04/10 - 2:42am

How can we forget about CNT+0....

Login or register to post comments

in response to: gamby

Muhammad Khojaye replied on Tue, 2009/04/14 - 12:19am

Go to line number N in the source file: Ctrl + L, enter line number

Go to the last edit location: Ctrl + Q for .

Go to a supertype/subtype: Ctrl + T

in response to: mark haniford

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

7 of 8 4/28/2011 5:16 PM

Page 8: Effective Eclipse_ Shortcut Keys _ Eclipse Zone

Advertising - Terms of Service - Privacy - © 1997-2010, DZone, Inc.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Login or register to post comments

Muhammad Khojaye replied on Tue, 2009/04/14 - 12:19am

Go to line number N in the source file: Ctrl + L, enter line number

Go to the last edit location: Ctrl + Q for .

Go to a supertype/subtype: Ctrl + T

Login or register to post comments

in response to: mark haniford

Rick Reumann replied on Tue, 2009/09/29 - 1:52pm

In regard to CTRL-F6 why did you mention " This is an slower alternative to Ctrl + E." To me,CTRL-F6 is a much 'faster' alternative to CTRL-E.

CTRL-E has things in some weird order whereas ctrl-F6 will first return you back to the last editorwindow (which is typically what I want), or if not that last one, usually one of the ones I've just workedon is near the top of the list.

How is ctrl-F6 slower than Ctrl-E ? Ctrl-F6 seems much more useful to me (I actually rebind it to ctrl-tab)

Login or register to post comments

Arun Ramakani replied on Wed, 2009/11/25 - 1:12am

Good work

Login or register to post comments

Lajos Doma replied on Wed, 2009/12/09 - 6:46am

Nice article!

I also found it useful to attach shortcut-keys to pre-configured perspectives. See my blog-entry: Eclipse:quickly change perspectives with keyboard shortcuts

Login or register to post comments

Ohad Nahum replied on Thu, 2010/12/30 - 12:27am

Thanks for the overview - very helpful. Maybe someone knows how to add a shortcut key that willinsert some lines of texts ? I want to insert a text template into my code whenever I press a shortcutkey.

Login or register to post comments

Javin Paul replied on Fri, 2011/04/08 - 9:30am

here is my list of Top 20 eclipse keyboard shortcuts I would rather say very useful and practical eclipseshortcut :) and I used it on day to day basis.

Login or register to post comments

Effective Eclipse: Shortcut keys | Eclipse Zone http://eclipse.dzone.com/news/effective-eclipse-shortcut-key

8 of 8 4/28/2011 5:16 PM