12

I know there is a trick that when you type quickly code in Eclipse, you can hit some secret keys and it will auto-complete the missing parts. Who knows them?

example: I have someVeryLongVariablesWhichIWantToTypeFast and I start typing someVeryLongVa but nothing happens. Only when I type method names a yellow box appears that wants to help me.

n00ki3
  • 14,529
  • 18
  • 56
  • 65

13 Answers13

21

Ctrl + Space is the autocomplete shortcut

All shortcuts you can find under Window -> Preferences -> General -> Keys

Peter Smit
  • 27,696
  • 33
  • 111
  • 170
13

As mentioned the command is Ctrl+Space to auto complete. You can speed it up using camelCase...so in your example:

someVeryLongVariablesWhichIWantToTypeFast

you could start typing sVL then Ctrl+Space should auto complete or list all variables that match.

CamelCase also works for specify classes, searching for classes etc.

Others I like/use:

type sysCtrl+Space to get System.out.println statement (or err)

type foreCtrl+Space after an array/list line to foreach it

Click on an argument to a method and Ctrl+1 to create a field for it and assign it, great for constructors

Ctrl+1 on any local variable to convert to field, split declaration, or inline it

if you have

object.method().method2().method3()

selecting object.method() and type Ctrl+1 to assign to a field or local variable, then you get

Object objLocal=object.method()
objLocal.method2().method3() 
//Can now select objLocal.method2() and do the same again
AntóinÓg
  • 511
  • 3
  • 19
8

My favourites:

  • Ctrl + Space - auto complete

  • Ctrl + 1 - show quick fix options when you are over an error / warning

  • Shift + Ctrl + L - list short cuts

Jasper
  • 2,166
  • 4
  • 30
  • 50
jjujuma
  • 22,055
  • 12
  • 44
  • 46
4

One trick that I love in Eclipse for Java is writing backwards (meaning you write the client before the code it calls). We typically think of autocomplete to help us with methods and variables that already exist. This is okay, but even cooler is when a method/class does not exist.

Try typing this code into a method (anywhere, really):

Who who = new Who();
who.whatUpMan("hi", 32);

Now left-click on the Who at the beginning. It will give you the choice to create a class, interface, enum, etc.

Now left-click on the whatUpMan. It will prompt you to create the method with the right parameter types and everything.

These are called "Quick Fixes" in Eclipse and they give you total freedom to code from the client "backwards" to classes it utilizes. And when you've already got the method, of course, control-space and control-shift-space (to see parameters for methods) are your friends.

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
  • 2
    I adopt this approach for writing tests. It's an example of how having tests can make your apis a lot easier to use, because they are designed from the user in. – Dan Gravell Aug 11 '09 at 11:07
3

http://eclipse-tools.sourceforge.net/EclipseEmacsKeybindings_3_1.pdf

ufukgun
  • 6,889
  • 8
  • 33
  • 55
3

Some more time savers that don't seem to be mentioned:

  • Ctrl+3 'Quick Access' which basically let's you reach anything without clicking around too much. E.g. type 'nav' in the popup dialog, rather than Window | Show View | General | Navigator or wherever it is.

  • Ctrl+O 'Quick Outline': when editing Java (and some other things), pops up a lighweight dialog so that you find anything in the file by a few keystrokes

  • Shift+Alt+T 'Refactoring', and things below that menu - look for shortcuts there, use 'Rename', 'Move', 'Extract method', 'Change method signature' often

  • Alt+Up/Down move blocks of code up/down without cut/paste

  • Alt+Shift+Up/Down select various levels of code (expressions,statements, methods, class) easily

  • Ctrl+1 on the selected code offers you cool stuff eg. Extract to variable/constant/method; Split variable declaration -- see others above, or just try it on anything

  • Ctrl+Shift+R find any file in the workspace, similar to Ctrl+Shift+T to find types

inger
  • 19,574
  • 9
  • 49
  • 54
2

Ctrl + Shift + O : resolve all dependances automaticall. In Java, it's a life saver as it cleans old packages and add the required one without a single line to write.

"Right click" then "refactor" : all the features are handy, but I espacially love "rename" (Ctrl + Shift + R, c.f comments) because it will apply the changes to all the project. No more tricky find / replace wit regexp to do ensure you breal nothing else :-)

"Right click" then "source" : equally useful, with a special mention to "generate getter and setter" and "implement methods"

Ctrl + D : delete a line. Kinda cool.

Jasper
  • 2,166
  • 4
  • 30
  • 50
Bite code
  • 578,959
  • 113
  • 301
  • 329
1

I kind of remember CTRL+SPACE was the shortcut for autocomplete.

slipbull
  • 1,477
  • 1
  • 11
  • 27
1

Another time-saver is formatting the code automatically using Ctrl + Shift + F.

Formatter preferences http://img187.imageshack.us/img187/5866/eclipseformatter.png

Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
  • That's a crutch! I use the space bar like a real cowboy! Just kidding, +1 for mentioning this feature. I use it in Netbeans for Ruby, PHP, HTML and Java. – Dan Rosenstark Aug 11 '09 at 14:23
0

General Eclipse tips

  • Get rid of all the crap that you'll never use
  • if you do web-dev ... install the database, php, pydev, modules and plugins
  • install svn/cvs/git plugin
  • use Trac
  • have different code enviornments for different code types, i.e. one for python-dev, c++, and so on.
  • wait a few weeks to months before updating
  • i have about 100 premade mini scripts that i use frequently.
  • learn to develop your own plugins, as it's easy and fun.
dassouki
  • 6,286
  • 7
  • 51
  • 81
  • 1
    That's great and all, but it doesn't really answer the question asked. not to mention it's pretty ambiguous. (What crap is he never going to use, and how does he get rid of it? What are some of your 100 frequently used scripts? etc...) Please stick to answering the question that was actually asked, and ensure that your answers are detailed enough that they can actually be followed to a solution. – Toji Sep 04 '09 at 17:45
0

For some applications, the answer is to generate the code using EMF. But the EMF learning curve is significant.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

Probably this might not exactly answer your question but it is very relevant to your question title.
You can define templates in Eclipse to magically type and get a bunch of code typed for you. For instance you may type something like syso or sout to get System.out.println() in your Java code.
This can be done by following Window -> Preferences -> Java -> Editor -> Templates. You can also add a Template View, which you find at Window -> Show View -> Other -> Search for Templates.
Here is an image to clarify
* Original related answer in here as well.

Hope it is helpful to someone :)

Community
  • 1
  • 1
Dani_NJ
  • 50
  • 1
  • 7
0

I would suggest go to Eclipse -> Preferences -> General -> Editor -> Keys and to configure your own keyboard shortcuts for all common tasks so that you can have custom keybindings that are perfect for you.

Arunabh Das
  • 13,212
  • 21
  • 86
  • 109