Let Eclipse suggest variable names with control-space keystroke

I just learned that Eclipse can automatically create (or suggest) variable names for you. The suggestions are based on the class of the object you're about to create, and any characters you've typed for the variable name so far.

For example, if I'm in a method and I type Connection, followed by a space, then press the [Control][Space] keys, Eclipse adds a variable named connection, so my line changes to Connection connection.

This feature gets even more interesting if you type one or two characters of the variable name, then press [Control][Space]. For example, if you type StringBuffer s, then press [Control][Spacebar], Eclipse gives you a drop-down menu with choices of stringBuffer and sBuffer, which is pretty cool.

As I've described in other blog postings, this same [Control][Space] keystroke provides a number of suggestions in Eclipse, generally falling into a category named content assist. Whatever you call it, I like it, because it saves me a lot of time and keystrokes.

 

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

It's been a while since I did this, but since I use ctrl+space to work in Eclipse on both of my Macs, I must have switched the Spotlight keystroke to command+space. You can do this by going into System Preferences, click the Spotlight icon, and then setting the "Spotlight menu keyboard shortcut" on the bottom of that panel.

You can also go into Eclipse and change the keystroke on that side to something else, but I prefer this approach, especially if you switch back and forth between Mac and Windows systems.

Hi Alvin, thanks for your reply! This is exactly what I found out after couple of minutes googling. I changed the hot key for spotlight to something else (dont remeber what exactly because I dont use it anyway) and replaced all short cuts in Eclipse to the windows-like settings. Your post put me on the right track though. Thanks a lot!

Cheers from Berlin, Germany

Johannes

Permalink

I am a long time user of Eclipse and just started using it on a Mac. I had no idea why Ctrl-Space did not work like it did on Windows (aka Windoze) platforms. I happy to have found your tip here. Getting the Eclipse shortcuts back is such a time saver.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.