Saturday March 18, 2006
Why am I Using NetBeans? Top Reason
CTRL-K and CTRL-L
Two most useful key shortcuts in NetBeans, which let me quickly autocomplete any words when editing any textual files (java, xml, html, etc). Like CTRL-P in Vim, they just search the matching words in open buffers either upwards (CTRL-K) or downwards (CTRL-L). Unlike CTRL-space autocompletion, their matching is not bound by lexical scope, and therefore quicker. For instance, when I am writing this:
String unitName = null; String userName = getUserNameFromRequest(); register(u //STOP TYPING! Press CTRL-K to autocomplete userName
Why is CTRL-K better than CTRL-spce, at least in this example? Well, if you press CTRL-space, you will see a pop-up window that includes at least two items in order: unitName and userName. Then you have to click on or scroll down to userName to select it. That's a lot of key strokes for such a simple operation!
What if I want to use unitName at the above cursor point? You just need to hold CTRL and press K twice. As you keep pressing K, NetBeans keep going upwards in your buffers. Not just the current file, but all the open files, so you can get a variable name from other files. This is equivalent to locating the other file, finding the variable in that file, copying it, coming back to your working file, and pasting it at the right cursor point.
Since CTRL-K and CTRL-L know nothing about lexical scope, they are very flexible and versatile:
Caution: as with any autocompletion techniques, you are ultimately responsible for choosing the correct one. In the above register(String userName, String unitName) method, if you erroneously choose (unitName, userName), even the compiler won't detect it.
BTW, after you autocompleted register(userName, you can just directly type ; without movig cursor to the end. It will automatically jump to the end of the statement. Of course,the ending ) was already there when you typed (.
Posted at 09:41AM Mar 18, 2006 by chengfang in NetBeans | Comments[5]
Posted by huntch on March 18, 2006 at 04:33 PM EST #
Posted by 61.144.54.43 on March 21, 2006 at 10:56 PM EST #
Posted by Henning Tegner on March 22, 2006 at 04:57 AM EST #
Posted by DataMajor on February 26, 2007 at 10:04 PM EST #
BTW, for those who have changed their keybindings (to eclipse for example) this is the Source/Insert Next/Previous Matching Words menu items
Posted by Stephen on July 22, 2009 at 05:32 AM EDT #