Gregg has posted 4 posts at DZone. You can read more from them at their website. View Full User Profile

Hidden Hippie

02.05.2008
| 4267 views |
  • submit to reddit
With more and more folks trying out the NetBeans IDE I continue to see hippie completion discussed out on the nbusers email list. So, it is worth discussing here because this feature is one of those that almost seems hidden - even though it is listed on the IDE's top level Source menu. This has been written about before - Tor Norbye wrote a blog entry on this topic, as did Charles Ditzel. It is mentioned in a tutorial by Randahl Fink Isaksen, and perhaps in other spots.

Tor pointed out that the name "hippie completion" originated with the feature in XEmacs. Wherever the name came from, the concept is simple: in response to a control key combination, the editor fills in the nearest matching string. So for example, using NetBeans 6.0, on line 21 of this source file:

I have typed in myBi as the parameter to System.out.println(). If I then press Ctrl-K the editor will search backwards through the edit window for the nearest match and will then fill in the rest of the string for me:

Note that the match is done without any sort of context knowledge. That is an important point because it means that hippie completion is not smart, at least not in comparison to a standard code completion feature. The upside though is that it is faster than code completion.

If I had instead pressed Ctrl-Shift-K then the editor would have searched forward in the edit window and would have wrapped around to the beginning of the file and continued searching until it found myBig:

Some things to note:

  • Press Ctrl-K (or Ctrl-Shift-K) repeatedly to have the editor suggest other strings that match.
  • You don't have to type anything before invoking the feature - if you do not give it anything to match then the editor will just suggest the string that is closest to the cursor position.
  • As mentioned, when it does its search the editor wraps around when it reaches the end of the file. It also wraps when it reaches the beginning. As a result, I always just use Ctrl-K, even when I want to insert a string that is further down in the file from where I am currently editing.
  • The editor searches all open editor windows for a match, not just the window for the file that currently has focus.
  • NetBeans has had this feature for years and years and prior to version 6.0 the keybindings were Ctrl-K to search backward and Ctrl-L to search forward. The addition of so many new features in NetBeans 6.0 required modifying the default keymap and the default forward search keybinding got changed from Ctrl-L to Ctrl-Shift-K.
  • The official names for these features are "Insert Previous Matching Word" (Ctrl-K) and "Insert Next Matching Word" (Ctrl-Shift-K). But I prefer to use the term "Hidden Hippie." :-)
5
Your rating: None Average: 5 (1 vote)
Published at DZone with permission of its author, Gregg Sporar.

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

Comments

Rick Ross replied on Tue, 2008/02/05 - 9:04pm

Hi Gregg,

I love the name "Hidden Hippie" - that's a great one to remember. It's really nice to see you here on NetBeansZone, and this is an excellent first posting. Thanks a lot!

Rick

PS - I had no idea there was such a distinction between the two forms of the feature. 

anjan bacchu replied on Wed, 2008/02/06 - 6:56pm

hi there,

 I've used hippie completion in emacs, eclipse and IDE. all these editors used the DEFAULT keystroke -- ALT + /. Howcome, netbeans thought that it could change the key to CTRL +K ?

 all hte same, good to know that netbeans is catching up in terms of editing capabilities -- especially with its macro capability as well.

 BR,

~A

Gregg Sporar replied on Wed, 2008/02/06 - 10:10pm in response to: anjan bacchu

 

>all these editors used the DEFAULT keystroke -- ALT + /. Howcome, netbeans thought that it could change the key to CTRL +K ?  

I'm not sure how you are defining the term "DEFAULT" - are you referring to the original implementation of this feature in emacs?  In other words, the first tool to pick a keystroke defines the default?  In any event, as with all the other keybindings, you can change the value that NetBeans uses so that instead of Ctrl-K it uses Alt-/ (Tools > Options > Keymap > Source > Previous Matching Word).

>all hte same, good to know that netbeans is catching up in terms of editing capabilities -- especially with its macro capability as well.

Thanks for the feedback.   And, uhm, just to set the record straight, as previously mentioned NetBeans has had this particular editor feature for many, many years.  :-)

- Gregg Sporar
 Technology Evangelist at Sun Microsystems

anjan bacchu replied on Fri, 2008/02/08 - 12:56pm

Hi gregg,

   thank you. would you expect all programs to honor COPY TO CLIPBOARD to be CTRL + C( or CTRL + INS), because either it is part of some standard(CUA) or convention ?

    If I have used a feature in an editor, like iterative name expansion, we tend to think that it is CTRL + SPACE. If XEmacs, Eclipse and IntelliJ
think "ALT + /" is the default key for hippie expansion, I'm wondering why Netbeans chose otherwise. If you want to make a feature available to your users, you don't want to give a different default shortcut. By using the same default keystrokes, you make an experienced IDE/editor user become productive
on your platform quickly.

    I understand that you can change the key bindings.

just my 2cents. 

Thank you,

BR,
~A
 

Gregg Sporar replied on Fri, 2008/02/08 - 6:19pm

>   If I have used a feature in an editor, like iterative name expansion, we tend to think that it is CTRL + SPACE. If XEmacs, Eclipse and IntelliJ think "ALT + /" is the default key for hippie expansion, I'm wondering why Netbeans chose otherwise.

 That's a fair question. The feature was put into NetBeans long ago before I joined the project (April 2005), so I don't have the background necessary to answer it.  I would point out, however, that we could not have used Eclipse as a guide, since Eclipse did not yet have the feature at the time it was added to NetBeans.  :-)

And not to start a flame war, but to me this is a bit different than something like Ctrl-C.  I say that because there are a number of good tools out there that either do not support hippie completion or like NetBeans use some other keybinding.  I'm not a TextMate user, but from looking around on the web it appears it does not exactly support this feature.  I have used jEdit and I know that its default is Ctrl-B.

 But your main point is still valid: it is all about productivity across tools.  Toward that end, NetBeans includes pre-configured key bindings  for both emacs and Eclipse.  Choosing either of those in the options dialog changes the IDE so that Alt-/ is the keybinding for hippie completion.

- Gregg Sporar

Technology Evangelist at Sun Microsystems

Matt Coleman replied on Fri, 2013/01/18 - 1:47am in response to: Gregg Sporar

Thanks for clarifying this issue Gregg...it's very helpful

buffalo freelance website designer 

Comment viewing options

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