tags:

views:

289

answers:

5

Is there any way to get "dumb" word completion in Eclipse, similar to ctrl+p in Vim?

For example, I often write a function call:

x = getMeAnXPlease();

Then go in to write the definition:

function getMe...

At which point, in Vim, I hit ctrl+p, which will complete the 'getMe' to 'getMeAnXPlease'.

Is there something similar for Eclipse?

Edit: I know that ctrl+space does a context-sensitive completion and ctrl-1 is the magic "fix this line" key... But there are situations where I just want context-insensitive completion... Which seems to be provided by the 'Word Completion' command.

Edit: Next question: is it possible to do context-insensitive line-completion (similar to c-x c-l in Vim)? That is, complete the current line with a similar line:

doSomeThing(1, 2, 3, 4);
doSome <c-x c-l> -- inserts the rest of the 'doSomeThing(1, 2, 3, 4);' line
+2  A: 

There is actually, it's called templates and there are a multitude of them, a lot more advanced than simple word completion. Look at:

Window --> Preferences --> Java --> Editor --> Templates

for a list of the current templates and the possibility to add more. You would then use Ctrl + Space for the completion to pop up. If you write "sysout" and press Ctrl + Space, for example, you get "System.out.Println([cursor here]);".

I wrote a sample one myself for adding Before functions to JUnit test cases:

@${testType:newType(org.junit.Before)} public final void setUp() throws Exception { ${cursor} }

Which would be triggered by typing "before" and Ctrl + Space.

Stefan Thyberg
+2  A: 

Ctrl+Space for completion

Ctrl+1 (or Cmd+1) for hints on the code snippet you are working on (like automatically create the missing method, etc.)

ivo
+3  A: 

Write x = getMeAnXPlease();

Wait a second until compiler understands there's no such method.

Hit Ctrl-1 and Enter - it will create full method body automatically.

Yoni Roit
+1 This is actually the easiest way of doing something as simple as the question entails.
Stefan Thyberg
Also, for this to work you'd have to have the cursor on the method, otherwise it won't work.
Stefan Thyberg
I'd love to, but I'm working in FlexBuilder which lacks any reasonable quick-fixing :'(
David Wolever
A: 

A little more detail on Quick Fix (Ctrl+1 or Cmd+1). Instead of going somewhere to start defining the new method, you can simply invoke Quick Fix from the place where you call the nonexistent method. It will create a new empty function with the correct name and leave your cursor in position to fill it in.

Carl Manaster
+1  A: 

Ah ha! Found it.

There is a 'word completion' feature which defaults to 'ctrl-.'.

David Wolever
interesting .. will have to try this out.
toolkit
FYI, word completion defaults to 'Alt+/' here on my german Windows XP. 'Ctrl+.' is used to navigate to the next problem marker.To see all commands type 'Ctrl+Shift+L'...'Ctrl+3' is really nice as well...
Martin Klinke
Yea, I came across ctrl+3 by accident... It's good stuff.Also, ctrl-. may be strange for me because I'm on a mac :P
David Wolever