Don't forget Ctrl+Shift+L, which displays a list of all the keyboard shortcut combinations (just in case you forget any of those listed here).
Ctrl-2 something Seems that nobody mentioned Ctrl-2 L (assign to new local variable) and Ctrl-2 F (assign to a new field), these ones have changed how I write code. Previously, I was typing, say (| is cursor location): Display display = new | and then I pushed Ctrl-Space to complete the constructor call. Now I type: new Display()| and press Ctrl-2 L, which results in: Display display = new Display()| This really speeds things up.(Ctrl-2 F does the same, but assigns to a new field rather than a new variable.) Another good shortcut is Ctrl-2 R: rename in file.
It is much faster than rename refactoring (Alt-Shift-R) when renaming things like local variables. Actually I went to Keys customization preference page and assigned all sorts of additional quick fixes to Ctrl-2-something. For example I now press Ctrl-2 J to split/join variable declaration, Ctrl-2 C to extract an inner class into top-level, Ctrl-2 T to add throws declaration to the function, etc. There are tons of assignable quick fixes, go pick your favourite ones and assign them to Ctrl-2 shortcuts.
Templates Another favourite of mine in my “npe� Template, defined as: if (${arg:localVar} == null) throw new ${exception:link(NullPointerException,IllegalArgumentException)}("${arg:localVar} is null"); This allows me to quickly add null argument checks at the start of every function (especially ones that merely save the argument into a field or add it into a collection, especially constructors), which is great for detecting bugs early. See more useful templates at www.tarantsov.com/eclipse/templates/.
I won't list them all here because there are many, and because I often add new ones. Completion A few code completion tricks: camel case support mentioned in another answer: type cTM, get currentTimeMillis default constructor: in the class declaration with no default constructor push Ctrl-Space, the first choice will be to create one overloading: in the class declaration start typing name of a method you can overload, Ctrl-Space, pick one getter/setter creation: type “get� , Ctrl-Space, choose a getter to create; same with “is�
And “set� Assign To A New Field This is how I add fields. If you have no constructors yet, add one.
(Ctrl-Space anywhere in a class declaration, pick the first proposal. ) Add an argument (| is cursor position): public class MyClass { public MyClass(int something|) { } } Press Ctrl-1, choose “assign to a new field�. You get: public class MyClass { private final Object something; public MyClass(Object something) { this.
Something = something; } } Add a null-pointer check if appropriate (see “npe� Template above): public class MyClass { private final Object something; public MyClass(Object something) { npe| this. Something = something; } } get: public class MyClass { private final Object something; public MyClass(Object something) { if (something == null) throw new NullPointerException("something is null"); this.
Something = something; } } A great time saver!
1 CTRL+2,F and CTRL+2,L rock my world now. Thanks – Joshua McKinnon Mar 17 '09 at 6:24 12 now if only your template used braces... – rsp Mar 30 '10 at 20:38 3 @rsp Sorry, I hate inserting unneeded braces. Btw, Eclipse has code cleanup feature that can make your code use any style of braces (always or only when needed), and it can apply it on save.
– Andrey Tarantsov Apr 1 '10 at 9:04.
Ctrl-shift-r and its buddy, ctrl-shift-t, to open a resource or type, respectively. Resources includes all files in your open projects (including non-java files), and types includes java types either in your projects, or in a library included in the projects.
6 ctrl+shift+r is nice also for opening types when you just opened a project since it doesn't need indexing. – boutta Mar 17 '09 at 6:36.
Crtl+1 is my favorite. The quick fixes for the red-squiggles. It is also located in the Edit Menu -> Quick Fix.
Ctrl+Shift+O to organize imports, which will format them nicely, remove unneeded imports, and add missing imports.
6 I noticed the other day that this can be used to organize the whole project or parts of it, not just one file as I had expected. Extremely useful. – Antti Sykäri Sep 12 '08 at 15:26 11 @boncey yes, it is configurable.
Note that since Eclipse3.3 you can ask Eclipse to automatically organize import during saves (Java > Editor > Save actions) – romaintaz Jan 30 '09 at 12:49.
Ctrl-J starts an incremental find. Then start typing. Use up/down to find previous/next instances of what you typed.
Ctrl-Shift-J searches backwards.
9 in the same vein select a word and hit ctrl-k or ctrl-shift-k and it will iterate through the selected string occurences – Newtopian Jun 8 '10 at 12:00.
Type 'syso' then press Ctrl+Space to expand it to System.out.println(). Tres handy.
1 According to this: syse will be expanded to System.err.println(); – furtelwart Mar 25 '09 at 13:20.
CTRL+3 brings up a type-ahead list of any menu command.
CTRL-SHIFT-g : finds usages of the method or field under the cursor, absolutely necessary for understanding code CTRL-F6 : navigate between the list of open editor windows, if you just type it once and let go you toggle back to the previous editor window, doing this successively is a nice way to jump back and forth CTRL-t : on a class or method will show you the type hierarchy, very useful for finding implementations of an interface method for example.
1 I use a 5 button mouse and map F6 to one of the buttons to make for quick navigation. – s_t_e_v_e Dec 31 '08 at 19:27 1 I know I can change it but I wish CTRL-F6 was something else by default. I can't hit it with one hand.
– Albert Feb 27 '09 at 16:25 1 F4 will also open the type hierarchy by default. Nice and conveniently placed next to F3, which jumps to the definition of whatever's under the cursor. – Mike Daniels May 18 '09 at 20:10 5 Remapping Ctrl-F6 to Ctrl-Tab is essential.
Very natural to understand, since it's like changing tabs in your browser. – espinchi Jun 30 at 13:28.
Clicking on the return type in a method's declaration highlights all exit points of the method. For instance: 1: public void foo() 2: { 3: somecode(); 4: if ( blah ) return; 5: 6: bar(); 7: } clicking on void will highlight the return on line 4 and the close } on line 7. Update: It even works for try{} catch blocks.
If you put cursor on exception in the catch block and eclipse will highlight the probable methods which may throw that exception.
Code completion supports CamelCase, e.g. , typing CWAR will show a result for ClassWithAReallyLongName. Start using this feature and you'll never type another long classname again.(parts copied from another answer because I think answers w/ just one hint/tip are best for polling).
Alt-Up Arrow moves the current selection up a line, Alt-Down Arrow moves it down. I also use Alt-Shift-Up/Down Arrow all the time. Ctrl-K and Ctrl-Shift-K is quite handy, finding next/previous occurrence of the current selection (or the last Find, if nothing is selected).
There's an option to place the opening curly brace and a semicolon automagically in the "correct" position. You'll have to enable this - Choose Window/Preferences and type "brace" in the searchbox - should be easily findable (no eclipse on this computer). The effect: Typing a semicolon anywhere on the line will place it at this lines end (as in word/openoffice: Backspace if you'd like to have it in the original place) Typing an opening curly brace when you're just inside another pair of braces will place it at the end of this line - as in this example ("|" is the cursor): if(i==0|) typing "{" now will result in if(i==0) {.
Ppie expand/Word Complete, afaik inspired by Emacs: will autocomplete any word in any editor based on other words in that file. Autocomplete inside String literals in Java code, in xml files, everywhere. Alt.
2 On a German keyboard, it's Alt + Shift + 7, because / is on the 7. – furtelwart Mar 25 '09 at 13:25.
Alt-Shift-R stands for rename, not refactor. Refactoring is a more general term (as defined by the book). Nevertheless, it is one of my favorite refactorings.
Others include: Alt-Shift-M: Extract Method (when a code block or an expression is selected) Alt-Shift-L: Extract Local Variable (when an expression is selected) Extract Local Variable is especially useful when I don't remember (or bother to type) the result type of a method. Assuming you have a method JdbcTemplate createJdbcTemplate() in your class, write some code such as this: void someQuery() { createJdbcTemplate() } Select the expression createJdbcTemplate(), click Alt-Shift-L, type the name of variable and press enter. Void someQuery() { JdbcTemplate myTemplate = createJdbcTemplate(); }.
5 note that the Alt-Shift-R rename does a "refactoring rename" rather than a "rename-in-file" – Scott Stanchfield Feb 26 '09 at 17:18 1 To assign the method result to a variable, you can use Quick fix (Ctrl-1) as well, without even selecting the method call. – Jorn May 31 '09 at 23:43.
Absolutely, Ctrl+Q to go to last edit location. It is very useful just after being interrupted by phone, boss or others.
Nobody's mentioned the best one yet. Click on a class or method name and press Ctrl+T. You get a quick type hierarchy.
For a class name you see the entire class hierarchy. For a method name you get the hierarchy showing superclasses and subclasses, with implementations of that method distinguished from abstract mentions, or classes that don't mention the method. This is huge when you are at an abstract method declaration and quickly want to see where it is implemented.
Alt+Shift+Up Arrow does escalating selection. Alt+Shift+Down does the opposite.
Ctrl + Shift + M: changes a static method or static attribute reference of a class to a static import. Before import X; ... X.callSomething(); After import static X. CallSomething; ... callSomething().
F3 has been my favorite, opens the definition for the selected item. Ctrl+Shift+R has an interesting feature, you can use just the uppercase camel letters from a class when searching (such as typing CWAR will show a result for ClassWithAReallyLongName). Alt+Shift+W > Package Explorer makes life easier when browsing large projects.
1 That camel case trick also works when writing code. Type CWAR in the editor then hit CTRL-Space and it will expand to ClassWithAReallyLongName. I'm going to add this as a separate tip if it's not there already.
– Darren Greaves Nov 19 '08 at 18:44.
A non-keyboard shortcut trick is to use commit sets in your Team->Synchronise view to organise your changes before committing. Set a change set to be the default, and all changes you make on files will be put in that set, making it easy to see what you have changed while working on a specific defect/feature, and other changes you had while testing etc.
Breakpoint on Exception Eclipse let you set breakpoints based on where an Exception occurs. You access the option via the "j! " icon in the debugging window.
The official help topic "Add Java Exception Breakpoint " has more on this. The Uncaught Exception option is to suspend execution when an exception of the same type as the breakpoint is thrown in an uncaught location. The Caught Exception option is to suspend execution when an exception of the same type as the breakpoint is thrown in a caught location.Do not forget the Exception Breakpoint Suspend on Subclass of this Exception: to suspend execution when subclasses of the exception type are encountered.
For example, if an exception breakpoint for RuntimeException is configured to suspend on subclasses, it will also be triggered by a NullPointerException.
CTRL+SPACE, for anything, anywhere. Generate getters and setters. Create Constructors using Fields Extract Method... Refactor->Rename CTRL+O for the quick outline.
CTRL+O+CTRL+O for the inherited outline. F4 to display a type hierarchy Open Call erarchy to display where a method is called from. CTRL+SHIFT+T to open a Java Type CTRL+SHIFT+R to open any resource.
ALT + left or right to go forward or backwards through edit places in your documents (easy navigation) Override/Implement methods if you know you're going to do a lot of methods (otherwise, CTRL+SPACE is better for one at a time selection. Refactor->Extract Interface Refactor->Pull up Refactor->Push down CTRL+SHIFT+O for organize imports (when typing the general class name such as Map, pressing CTRL+SPACE and then selecting the appropriate class will import it directly for you). CTRL+SHIFT+F for formatting (although Eclipse's built in formatter can be a little braindead for long lines of code) EDIT: Oh yeah, some debugging: F5: Step into (show me the details!) F6: Step over (I believe you, on to the next part...) F7: Step out (I thought I cared about this method, but it turns out I don't, get me out of here!
) F8: Resume (go until the next breakpoint is reached) CTRL+SHIFT+I: inspect an expression. CTRL+SHIFT+I+CTRL+SHIFT+I: create a watch expression on the inspected expression. Conditional breakpoints: Right click a breakpoint and you may set a condition that occurs which triggers its breaking the execution of the program (context assist, with Ctrl+Space, is available here!
) F11 - Debug last launched (application) CTRL+F11 - Run last launched (application).
Ctrl+Alt+UP or Ctrl+Alt+DOWN to copy lines.
12 Unless it gets intercepted by your video driver, and you end up with an upside-down screen. – Adam Jaskiewicz Feb 27 '09 at 16:26.
1 Alt+Shift+R is Refactor->Rename. There are several other refactoring shortcuts in Eclipse. – MetroidFan2002 Sep 16 '08 at 6:01.
Ctrl+Alt+H on a method to get the call hierarchy for it. Fast way to see where it is called from.
Not so dden but IMO the best Trick. Assuming Default Settings (and you have'nt added new snippets) ghlight (or select) a Text (String or Variable)...Press Ctrl+Space. The "sysout" snippet is triggered which wraps the selection around as its parameter.Eg."hello world!
" becomes System.out. Println("hello world!"); I love it so much that i've implemented a similar snippet for Android's Toast and Log.i() HUGE Time saver during Manual Debugging....
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.