Ask HN: Awesome/neat/favourite Eclipse techniques?
8 comments
I don't know if these are techniques rather then hotkeys, but I actively use the following (Note: I'm not really a big fan of IDEs, but use them professionally to conform to my work environment and Eclipse, while somewhat bloated, is very pleasant and gets better with every milestone).
Debugging:
Learn the hotkeys for stepping in (F5) over (F6) out (F7) and continuing (F8), I get super frustrated watching people click on the icons. Really helped the transition from debugging with the likes of gdb.
Conditional Breakpoints are a revelation.
Remote Debugging is great (I've been able to debug remote java processes, Lotus Notes (yuck) instances, Eclipse workbenches (for plugin development), Remote Perl Server Code (with E-P-I-C and Padwalker)... Eclipse's debugger interface is amazing.
Text Editing w/ Java and CDT:
CTRL+W : close active editor
CTRL + Space : Autocomplete (mentioned earlier)
CTRL + SHIFT + O : Organize Imports (Finds classes that should be imported, removes excessive imports, etc...probably one of the most justifiable reasons to use an IDE for Java development)
ALT + SHIFT + J: Add Javadoc in context
CTRL + SHIFT + G : Does a search on the highlighted text's context (i.e.) a method name to show where it is used.
F3 : Navigates to selected context (Method, class, variable, etc.)
CTRL+SHIFT+T : Presents Dialog for searching through Types (works in most perspectives), i.e.: Searching for a particular java class.
F4: Show the Type Hierarchy (subclass/superclass information)
Import & Export wizards are your friend (Creating java jars, exporting projects to archived zips).
Eclipse can be used to track history (kind of like your own personal lazy SCM). If you make a mistake you can right click on a file and perform "Replace With > Local History..." (this may need to be enabled in preferences). You can also Compare to history well.
Tasks : The 'Mylyn' plugin is great for GTD and Task management. I was a bit apprehensive at first, but it's pretty incredible, especially if you are a nut about keeping organized. You can create tasks, and assign your current work to it, and it will track and remember context (what classes you used) as you work on that task. Mylyn also interfaces with Bug Trackers like Bugzilla and JIRA.
Debugging:
Learn the hotkeys for stepping in (F5) over (F6) out (F7) and continuing (F8), I get super frustrated watching people click on the icons. Really helped the transition from debugging with the likes of gdb.
Conditional Breakpoints are a revelation.
Remote Debugging is great (I've been able to debug remote java processes, Lotus Notes (yuck) instances, Eclipse workbenches (for plugin development), Remote Perl Server Code (with E-P-I-C and Padwalker)... Eclipse's debugger interface is amazing.
Text Editing w/ Java and CDT:
CTRL+W : close active editor
CTRL + Space : Autocomplete (mentioned earlier)
CTRL + SHIFT + O : Organize Imports (Finds classes that should be imported, removes excessive imports, etc...probably one of the most justifiable reasons to use an IDE for Java development)
ALT + SHIFT + J: Add Javadoc in context
CTRL + SHIFT + G : Does a search on the highlighted text's context (i.e.) a method name to show where it is used.
F3 : Navigates to selected context (Method, class, variable, etc.)
CTRL+SHIFT+T : Presents Dialog for searching through Types (works in most perspectives), i.e.: Searching for a particular java class.
F4: Show the Type Hierarchy (subclass/superclass information)
Import & Export wizards are your friend (Creating java jars, exporting projects to archived zips).
Eclipse can be used to track history (kind of like your own personal lazy SCM). If you make a mistake you can right click on a file and perform "Replace With > Local History..." (this may need to be enabled in preferences). You can also Compare to history well.
Tasks : The 'Mylyn' plugin is great for GTD and Task management. I was a bit apprehensive at first, but it's pretty incredible, especially if you are a nut about keeping organized. You can create tasks, and assign your current work to it, and it will track and remember context (what classes you used) as you work on that task. Mylyn also interfaces with Bug Trackers like Bugzilla and JIRA.
CTRL + SHIFT + O : Organize Imports (Finds classes that should be imported, removes excessive imports, etc...probably one of the most justifiable reasons to use an IDE for Java development)
is by far my favourite reason to use Eclipse ^_^
is by far my favourite reason to use Eclipse ^_^
CTRL+O - My favorite eclipse command. Gives you autocomplete outline of the current class in a popup.
These three are essential for my workflow. When I am spinning up on code, I tend to open a LOT of files (select all, open) and scan them, kind of try to boot up the code into my head. This is how I navigate around.
CTRL+M - maximizes current editor
CTRL+E - Autocomplete list of open editors
CTRL+W - close current editor
Make sure to note that you can drag an editor next to another editor and get emacs-style multiple panels. You can also right click on the name of a class in the editor and select new editor - this gives you two editors on the same file, a key feature for legacy projects.
Make sure to customize code cleanup and warning settings to match your particular style.
Also, remember that the key to using eclipse is the plugins. One of my favorites is Mylyn, which integrates to most task management systems. This allows you to associate a set of files with a bug, which makes regression bugs a dream.
CTRL+T gives a similar functionality as CTRL+O, but for type hierarchy. Great for inheritance addicts.
CTRL+1 I am sure you have figured out and CTRL+Space too.
You can enable line numbers by right clicking in an editor.
Code folding is a great technique for highlighting what you are working with.
Eclipse keeps its own local history, so if you screw up before committing, it sometimes gives you an out.
and speaking of out, that's all that comes to the top of my head...
These three are essential for my workflow. When I am spinning up on code, I tend to open a LOT of files (select all, open) and scan them, kind of try to boot up the code into my head. This is how I navigate around.
CTRL+M - maximizes current editor
CTRL+E - Autocomplete list of open editors
CTRL+W - close current editor
Make sure to note that you can drag an editor next to another editor and get emacs-style multiple panels. You can also right click on the name of a class in the editor and select new editor - this gives you two editors on the same file, a key feature for legacy projects.
Make sure to customize code cleanup and warning settings to match your particular style.
Also, remember that the key to using eclipse is the plugins. One of my favorites is Mylyn, which integrates to most task management systems. This allows you to associate a set of files with a bug, which makes regression bugs a dream.
CTRL+T gives a similar functionality as CTRL+O, but for type hierarchy. Great for inheritance addicts.
CTRL+1 I am sure you have figured out and CTRL+Space too.
You can enable line numbers by right clicking in an editor.
Code folding is a great technique for highlighting what you are working with.
Eclipse keeps its own local history, so if you screw up before committing, it sometimes gives you an out.
and speaking of out, that's all that comes to the top of my head...
>> "especially the ones that were most convicted about how futile it is to write Java without Eclipse (or at least, one of the big three IDEs) - convinced me to give it another go."
I've been writing java for about 10 years and have tried an IDE once or twice. Horrible experiences.
Most of my code has been written using jedit/textmate. Syntax highlighting is all you need really.
Personally, I'd advise you go back to using a text editor. The myth that you need an IDE to code java is just silly.
Go back to the command line+text editor.
I've been writing java for about 10 years and have tried an IDE once or twice. Horrible experiences.
Most of my code has been written using jedit/textmate. Syntax highlighting is all you need really.
Personally, I'd advise you go back to using a text editor. The myth that you need an IDE to code java is just silly.
Go back to the command line+text editor.
I started programming as a young man on Visual Studio programming in VB and C++. There came a day years ago where I had to work with a text editor and a terminal on an AIX system and was surprised at how little I knew in terms of compiling, building, and programming in general (how is a class structured again? What packages/headers do I need to reference? What directories do my files have to be in? Why isn't my code running?). I think it's important that those who code exclusively in IDEs step back every now and then and understand how these 'auto-magic' functions IDEs provide work. I've now spent years using IDEs in addition to my own custom environment (I switch back and forth between vi, gedit, and textmate (when i'm on a mac) and make extensive use of sed/awk and other CLI commands to do custom activities that IDEs certainly cannot provide).
IDEs bring a lot to the table, but I can't help but agree with you in that it can be a horrible experience, especially to those who are accustomed to having complete control over everything in their environment. I think it's great for getting things done efficiently, but developing exclusively with them can bring a close-minded view of how things work.
IDEs bring a lot to the table, but I can't help but agree with you in that it can be a horrible experience, especially to those who are accustomed to having complete control over everything in their environment. I think it's great for getting things done efficiently, but developing exclusively with them can bring a close-minded view of how things work.
You read the article I linked to, right? I can hardly disagree. Nevertheless, after writing code that way for so long and being a very zealous old-school UNIX guy, I guess I'm interested in trying a newer, more conventional way of doing things.
'more convenient' often means far more trouble in the long run.
I've seen colleagues use their IDE build process which is completely broken, and spend a day trying to figure out what's wrong... (Never use a build process in an IDE). You see people blindly creating source files that are thousands of lines long and not noticing since their IDE folds the code etc. The IDE hides the bloat. Which is a terrible thing.
When you start trying to integrate svn, build process, etc into an IDE, everything goes wrong.
The 'intelligence' in textmate was even too much for me. Inserting "" when I pressed it once, trying to do code indenting. It still drives me mad how it handles tab and spaces (When I press delete, I want it to remove one space. Not 4).
I really don't think an IDE is 'more conventional'. Perhaps in corporate cubeville.
I've seen colleagues use their IDE build process which is completely broken, and spend a day trying to figure out what's wrong... (Never use a build process in an IDE). You see people blindly creating source files that are thousands of lines long and not noticing since their IDE folds the code etc. The IDE hides the bloat. Which is a terrible thing.
When you start trying to integrate svn, build process, etc into an IDE, everything goes wrong.
The 'intelligence' in textmate was even too much for me. Inserting "" when I pressed it once, trying to do code indenting. It still drives me mad how it handles tab and spaces (When I press delete, I want it to remove one space. Not 4).
I really don't think an IDE is 'more conventional'. Perhaps in corporate cubeville.
I guess I avoid some of these pitfalls because I wrote C and Perl with vi for 10 years, and used a relatively spartan FVWM environment consisting solely of terminals and command-line approaches to all problems.
That method of approaching programming and technical work isn't going to change for me even if I forklift-upgrade my Java text editor to something a little fancier, which is essentially what I see myself to have done here.
I can't use an integrated build process anyway because I'm working on a backend server process that necessarily must reside on a remote machine; there'd be virtually no point in trying to develop or run it locally, as it depends on connectivity to too many other resources for any aspect of its functionality. So, I mount the source directory over SSHFS or NFS and edit it "locally" with Eclipse, but the build process is remote and done via a manually crafted Ant build file.
I haven't seen Eclipse fold any code other than the big comment block at the top of every source file.
I wouldn't be opposed to integrating SVN awareness into it, but find it a bit problematic since I'm using SVN over SSH.
That method of approaching programming and technical work isn't going to change for me even if I forklift-upgrade my Java text editor to something a little fancier, which is essentially what I see myself to have done here.
I can't use an integrated build process anyway because I'm working on a backend server process that necessarily must reside on a remote machine; there'd be virtually no point in trying to develop or run it locally, as it depends on connectivity to too many other resources for any aspect of its functionality. So, I mount the source directory over SSHFS or NFS and edit it "locally" with Eclipse, but the build process is remote and done via a manually crafted Ant build file.
I haven't seen Eclipse fold any code other than the big comment block at the top of every source file.
I wouldn't be opposed to integrating SVN awareness into it, but find it a bit problematic since I'm using SVN over SSH.
I've been writing java for a bit over ten years myself and I love eclipse. You're sitting here writing code in this language that is known to be extremely verbose and you want to type it all by hand, refactor it all by hand, navigate it all by hand? Now THAT is silly.
>> "that is known to be extremely verbose"
It's not in my opinion, and yes, I do want to do it by hand. That's why my code is NOT extremely verbose.
It's not in my opinion, and yes, I do want to do it by hand. That's why my code is NOT extremely verbose.
So, when you use library classes, you write each and every single import manually? As in type in the package name and class name? That alone would mean a 20% drop in productivity for me. Ctrl-space is my lifesafer.
One of the major advantages of moving to a language aware IDE are the refactoring tools!
Rename: Alt + Shift + R (utterly invaluable)
Extract Local variable: Alt + Shift + L (Very handy for adding self documentation on complex expressions)
Inline: Alt + Shift + I
Move: Alt + Shift + V
Display Refactoring Context Menu: Alt+Shift+T
Another sweet feature I'd like to mention is Mark Occurrences - if find this invaluable for rearranging method bodies. For example, placing declarations closer to usage.
You can also distinguish reads and writes by configuring different highlight colours (Preferences->Java->Editor->Mark Occurances->Write Occurances).
I love eclipse.
Rename: Alt + Shift + R (utterly invaluable)
Extract Local variable: Alt + Shift + L (Very handy for adding self documentation on complex expressions)
Inline: Alt + Shift + I
Move: Alt + Shift + V
Display Refactoring Context Menu: Alt+Shift+T
Another sweet feature I'd like to mention is Mark Occurrences - if find this invaluable for rearranging method bodies. For example, placing declarations closer to usage.
You can also distinguish reads and writes by configuring different highlight colours (Preferences->Java->Editor->Mark Occurances->Write Occurances).
I love eclipse.
My personal favorite are the Templates in Preferences > Java > Editor > Templates
Ex: type in sysout hit CTRL + Space and it will convert sysout into System.out.println();
In regards to shortcuts, the ones I use most are:
Ex: type in sysout hit CTRL + Space and it will convert sysout into System.out.println();
In regards to shortcuts, the ones I use most are:
CTRL + ALT + UP/DOWN to duplicate a selected block of code and paste it above/below
CTRL + D to remove the line
ALT + UP/DOWN to move the current line up or down
On a related note, has anyone found a way to CTRL + Tab between opened documents?I'm just hitting eclipse after a long stint in Visual Studio. Favorite feature so far: hit ctrl+3 to give you a quicksilver-like command line full of useful stuff. The completion is a little finicky, but it's good enough to be useful. Also, Ctrl+Shift+R, I think, lets you open a file by typing in its prefix.
both very useful! I never used CTRL+3 before, I always intend to research eclipse more thoroughly but never get around to it
I've got a question: Is it possible to make Eclipse SVN-aware even when SVN-over-SSH (SVN over SSH remote command transport, aka svn+svn://user@host/path/to/repository URI scheme) is being used?
As far as I remember, both Subcplise (the older SVN plugin) and Subversive (the recommended SVN plugin for the latest Eclipse) support svn+ssh URLs. See http://www.eclipse.org/subversive/documentation/teamSupport/...
I know it's possible, because I did it a few years ago. As I recall, I installed a plugin.
Unfortunately, that's all I remember - I haven't used Eclipse in several years.
Unfortunately, that's all I remember - I haven't used Eclipse in several years.
i'm thinking that the Subclipse plugin (http://subclipse.tigris.org/) provides this. I've used this in the past, but through http.
Emacs key-bindings saved my life
I'm the n00b that posted this question a while back ("Reasonable Java editor for heavily CLI-oriented UNIX types who hate bloat?"): http://news.ycombinator.com/item?id=597213
Well, your responses - especially the ones that were most convicted about how futile it is to write Java without Eclipse (or at least, one of the big three IDEs) - convinced me to give it another go.
Sure enough, I upgraded all my hardware to relatively contemporary 64-bit gear, stocked up on some additional gigabytes of RAM, and now I'm happily writing all my Java in Eclipse. You were right.
I'm getting the sense, however, that despite my curiosity and occasional perusal of the documentation, I'm probably not taking advantage of some of the neatest things you can do with it.
About 90% of the time, I'm using it the same way I used to edit Java in a text editor. Oh, sure, the highlighting is nice, and I often use the package hierarchical view to navigate to classes or methods -- handy. The auto-indentation, cleanup, templates for common phenomena (try/catch, etc.), assistance in adding imports for unresolved class names, and other little things are all helpful. As some of you pointed out, the refactoring stuff can be pretty good; doing a mass-rename of a method with one click sure beats doing it by hand, or with a one-liner in the shell.
Still, I don't feel like I'm getting that much use out of it compared to just writing the code in a shell. My intuition tells me I should be doing more. If you have any tricks you find exceptionally useful or other productivity hacks that are less than entirely obvious, I'd love to know about them.
Thanks in advance!