How to Manage Keyboard Shortcuts in Eclipse and Why You Should
Join the DZone community and get the full member experience.Join For Free
when i use eclipse i try and use shortcuts all the time. they really make me work faster and give me time to focus on getting the code out rather than slowing down to invoke ide commands with the mouse.
because people work differently and on different things, it’s important to manage keyboard shortcuts to suit the way you work. so it’s good that eclipse makes it really easy to change shortcuts and also to view shortcuts for the commands you use a lot.
i’ll discuss how to change keyboard shortcuts, how to avoid conflicts with existing ones, why it’s a good thing to manage shortcuts and then end off with some examples of common shortcuts that you should add to you arsenal.
how do you manage keyboard shortcuts
the main preference page can be found under window > preferences > general > keys (or faster: press ctrl+3 , type keys and press enter ). from here you can see all commands and assign/change their associated keyboard shortcuts. in the video, i’ll show you how to reassign a key. we’ll use this to assign ctrl+tab to switch to the next editor.
- you don’t have to copy a command to assign/reassign a shortcut. i just prefer to keep the old shortcut in case someone else wants to take over my keyboard and expects the shortcut to work.
- all commands registered with eclipse are listed on the keys preference page. browse through them or search to see if your favourite command is listed. if it doesn’t have a shortcut assigned, then assign one immediately.
- the when dropdown on the dialog shows you in which context the command applies (eg. only when editing java source). you can assign the same shortcut to two different commands, but if the context differs eclipse will only execute the one command. i suggest you don’t change the context.
- notice that eclipse shows you which keys conflict with the selected one if their in the same context.
but all the keys are already taken
no, they’re not. firstly, if a key you like is already taken then be creative. use combos like ctrl+alt, alt+shift or even alt+shift+ctrl (easier to press then you think). these aren’t used as often as ctrl or ctrl+shift. you can sort by binding to see which keys are already used.
secondly, eclipse allows you to assign a sequence of keystrokes to a command. eg. alt+shift+x, j (that’s used to run the current class as a java application) is invoked by pressing alt+shift+x, releasing the keys then pressing j. if you forgot your sequence shortcuts, just press the first part (eg. alt+shift+x), wait a second then eclipse helps you out by listing all commands that have this keystroke as the first part of the sequence. the list appears in the lower right corner of the window. this works for any commands assigned a sequence of keystrokes.
here’s an example of what you might see when you press the first sequence of keystrokes (notice the list in the lower, right corner).
tip: for custom commands you want to assign, use a well-known first keystroke to group your commands. for example, i use alt+shift+b (b for byron) as my grouping prefix. this way there are fewer conflicts with existing shortcuts and eclipse can show me a quick list if i forgot which keys i used.
so why bother managing keyboard shortcuts
managing keyboard shortcuts in eclipse is important because:
- not all eclipse commands have assigned shortcuts. a command you frequently use could be assigned a shortcut. eg. an svn commit is registered as an eclipse command but doesn’t have a keyboard shortcut assigned. assigning one yourself will speed up checking in changes.
- sometime eclipse gets it wrong. a good example is ctrl+f6 for switching editors – ctrl+tab is a much more sensible option since the keys are close together and doable with one hand.
- going through the list of shortcuts may give you ideas for working faster or even show you a command you didn’t know eclipse could do.
but don’t shortcuts take a long time to learn?
no ways! i often hear people complain that it takes too long to learn the shortcuts. i assure you that the 5 minutes it takes to learn the shortcut saves you hours, even days, of work over the months and years that you’ll be working on eclipse. here are some tips to get into and improve your keyboard usage:
- start by learning the shortcuts for the things you do often. are you using the mouse a lot to launch applications or select code? well, there’s a shortcut to launch apps and one to select code faster.
- keyboard shortcuts are often indicated next to menu items. note them and try to use them instead of reaching for the mouse.
- learn to punish yourself when you reach for the mouse by undoing your action and forcing yourself to use the keyboard. this seems counterproductive (and harsh) at first, but it forces your brain to rewire itself so you’ll favour the shortcuts instead of the mouse the next time.
- there is an eclipse plugin called mousefeed that shows you a keyboard alternative to a mouse click you performed. you can also configure it to cancel mouse clicks where a keyboard alternative is available, forcing you to use the keyboard in those instances. i don’t use it personally but what i’ve seen looks good. it’s definitely sounds like a good idea if you want to change your mousey ways and it relates nicely to my previous point.
also keep this in mind: one of the easiest, surefire ways to work faster is to reduce the number of times you move your hands between the keyboard and mouse. the key is doing as much as possible with either one. for the mouse there are things like mouse gestures (if you’re on windows, try strokeit ). for the keyboard there are keyboard shortcuts and eclipse has hundreds of them ready to make your life easier (also see the excellent autohotkey for other ways to boost your keyboard usage).
examples of useful keyboard shortcuts
there are way too many shortcuts to list and you’ll come across the more useful ones in other tips . here are some you should get acquainted with at first and try to use all the time.
|ctrl+1||quick fix list (for resolving errors/warnings) and also refactoring|
|ctrl+space||display the autocomplete list to select a relevant method/template, etc.|
|ctrl+3||open quick access which allows you to run commands and navigate views and dialogs by searching for them, similar to launchy on windows or quicksilver on mac.|
|ctrl+shift+r||open any resource in the workspace, eg. xml file, class file, etc.|
|ctrl+shift+t||open a java type, eg. a class or interface.|
|f3||go to the declaration of the method/class/variable|
|f11/ctrl+f11||debug/run the last launched application (see this tip for more information)|
|ctrl+alt+h||display all methods that call a method (call hierarchy)|
|f2||show javadoc for the current element (shift+f2 shows external javadoc)|
|alt+up/down, alt+shift+down, ctrl+d||move a line up/down, copy a line, delete a line (see this tip for more information)|
|ctrl+/||comment/uncomment the current line or selected lines. you can be anywhere in the line, not necessarily at the beginning.|
you can press ctrl+shift+l to get a list of registered keyboard shortcuts in the lower right corner. but for a complete list, i prefer to go to the preference dialog as i can see all commands that are registered, even if they don’t have shortcuts registered
Opinions expressed by DZone contributors are their own.
How AI Will Change Agile Project Management
Java Concurrency: Condition
5 Common Data Structures and Algorithms Used in Machine Learning
Stack in Data Structures