Mac Keys for Eclipse

Mac OS X is special. Mac OS X has it’s own nice looking user interface. But it also differs from other operating systems in the way you move the cursor with the keyboard. All those Cocoa (and most Carbon) applications respect the key bindings of Mac OS X. The key bindings are even documented in the Apple Human Interface Guidelines.

So you are in luck when you have to work with XCode, TextEdit, … but when you have to write Java code there comes….. oh yes …. Eclipse.

Eclipse is this bombastic Java IDE which looks like a Windows app on each platform it supports. The Mac seems not to be the primary platform for Eclipse. :-)

And Eclipse does NOT respect the default key bindings of Mac OS X (a bug is already submitted). Someday when I over and over again used the Eclipse shortcuts in XCode and the Mac OS shortcuts in Eclipse I started to change the key-bindings in Eclipse to be a little bit more “Mac”.

It’s a progress in work and at the moment I changed only the bindings to move the cursor and for searching.

  • Select text to line start/end: Command-Shift-Left and Command-Shift-Right
  • End of text: Command-Down
  • Start of text: Command-Up
  • Line start/end: Command-Left and Command-Right
  • Page Down/Page Up: Option-Down and Option-Up
  • Page Down/Page Up: Option-Page-Down and Option-Page-Up
  • Previous/next word: Option-Left and Option-Right
  • Find Next: Command-G
  • Find Previous: Command-Shift-G

Installation:

  1. Download the File org.eclipse.ui.workbench.prefs.zip and unzip it.
  2. Copy the unzipped file org.eclipse.ui.workbench.prefs to your Workspace subdirectory “.metadata/.plugins/org.eclipse.core.runtime/.settings/”. The “.metadata” directory is by default hidden in Finder. Use the terminal to copy the file to the desired location.

Note: Eclipse shall be stopped before replacing the file. You may have done already some changes to the eclipse workbench configuration which may be lost when you replace the prefs file. It work’s for me but I am not responsible for any damage that results from using this prefs file. I’ve used this file with Eclipse 3.1.1.

If you add/change more key bindings please give me a favor and send the prefs file back to me at “martin” on this domain. I’ll link to the latest and greatest prefs file here.

Update: As Douglas mentioned in his comment below there is an easier way to share the key bindings. To use the preferences-import feature of eclipse use this preference-export-file. You have to unzip the file before importing. Thanks a lot for this tip!

13 Responses to “Mac Keys for Eclipse”

  1. Philippe Lamote Says:

    Hi Martin,
    Thanks a bunch for the effort already. Hopefully this is integrated by default in the next Eclispe.
    In the mean time, you solved something that has been irritating me a few times EVERY second using Eclipse.
    You’re my hero for today ;-) Bye,
    Philippe

  2. Douglas Pollock Says:

    It is possible to export the keys preferences on their own. You can go to “File > Export” and export Preferences. Then select the Keys Preferences option.

    Out of curiousity, how do you think we should approach the problem of the two different types of selection on MacOS X? Some selections work the same as selections on other platforms. Other selections are “non-reducible” (e.g., pressing the arrow key in the opposite direction expands the selection rather than shrinks it).

  3. martin Says:

    Of course it would be nice to have a complete conformance to Mac OS X key bindings for Eclipse. Unfortunately I think that this would be a lot of work to do and I am not sure if this could ever be a 100% solution.
    Eclipse is using Carbon. Because Cocoa provides features that are not available to Carbon by default there is already a gap (e.g. Option-Click rectangular text selection). I don’t know the underpinnings of Eclipse but I think there will be other gaps because Eclipse/SWT is “rewriting” some UI-controls (e.g. I couldn’t find a way to do a page down without cursor movement).
    Therefore I would do the easiest part first. It would help a lot if those key bindings that can be done Mac like today are made available to Mac users. I think this would solve more than 90% of the problem. A separate key-binding scheme that the user may choose would be the best.

    Regarding the text selection. I’m for myself okay with the current implementation in Eclipse. There are a lot of different ways to select text on Mac OS X and I am using just some of them right now. For now I would stick with the current implementation and concentrate on the easier parts. :-)

    @Philippe: I’m happy that this helped you!

  4. Danil Says:

    That’s cool!
    Thanks a lot.

  5. Tanrei Software Blog » Blog Archive » Eclipse Key Bindings and Mac OS X Says:

    […] There are some clues as well as a solution to this problem over here, http://www.martinkahr.com/2006/02/13/mac-keys-for-eclipse/. […]

  6. Jonas Due Vesterheden Says:

    Thanks, this was great.

  7. Peter Says:

    Thanks for this great help… Made the whole eclipse feeling a lot better! :-)

    You probably already noticed that [spacebar] will not toggle checkboxes. This is driving me close to madness as that’s the only think I need a mouse for aarg

    For example in ‘Generate Getters and Setters’ …

    Is this issue solvable?

  8. martin Says:

    I don’t know of any way to solve the “Spacebar” problem in certain dialogs. The best thing would be to fill a bug on eclipse.org on that :-)

  9. EclipseDoode Says:

    Anyone know how to turn off Eclipse’s use of HELP key? I’d like to bind it to insert or paste and can’t seem to get it working. I was able to remap OSX’s use of the key but Eclipse seems to have it hardcoded to display help.

  10. Teclas Mac para o Eclipse « bartolom.eu Says:

    […] Fonte: http://www.martinkahr.com/2006/02/13/mac-keys-for-eclipse/ […]

  11. Andre Says:

    martin: Work is now being done towards a Cocoa based version of SWT: http://www.eclipse.org/swt/

  12. Anonymous Says:

    Thanks for the info Andre.
    Cocoa is for sure the way to go. Now that the Java-Cocoa bridge is deprecated, SWT-Cocoa will be the way to write Cocoa apps with Java.
    I’m looking forward to it.

  13. gabe Says:

    Just a note:
    shift+z should redo