Eclipse Tip: Use Bookmarks to track important places in your code

A nice feature in Eclipse that is somewhat hidden is the bookmarking feature. It lets you keep track of important places in your code and get back to them.

For example, let’s say you’re reading some code and you notice a nice algorithm. Or you’re looking for where something specific is happening, like calling a certain web service that is critical and you find it. Or whatever piques your interest.

You could rely on the navigational features of Eclipse to get you back to that code, but that could mean a lot of presses on the back button. You could put in a // TODO , which adds an item to the Tasks view, but when you just want to remember where something is, that is an awkward way to get back to it.

So, instead, use Bookmarks. The only problem is that isn’t an obvious feature in Eclipse, like it is in say IntelliJ.

There’s really only a few things to learn though.

First, to add a bookmark, navigate to an interesting line of code, and then click on Edit | Add Bookmark… from the main menu. A dialog box will pop up asking you for a name. You should see a little blue bookmark appear in the left hand column and if you look carefully, you will also notice a little green rectangle in the right hand column.

Second, show the Bookmarks View. In my opinion, this should be on by default in the Java and Plug-in Development Perspectives, just like the Problems view. To see the Bookmarks View, select Window > Show View > Other… from the main menu. This will bring up a “Show View” dialog. Open up the “Basic” category, select “Bookmarks”, and press the OK button. You should see the bookmark you created in step one.

Third, when you find that you need to go back to your bookmark, just switch to the Bookmarks View and double-click on the bookmark you want to go back to. Note that from this view, you can also single-click to edit or delete with the red “X”. You can also sort and filter if you’ve got a lot of bookmarks.

Fourth, set up a keyboard shortcut for Adding a Bookmark. If you look at the useful Eclipse 3.0 full keyboard shortcut reference from the Eclipse Tutorial by Enrique (available in both Español and English.), you’ll notice that there is not a keyboard shortcut for Add Bookmark in the default Eclipse 3.0.1 install. (And it’s not there in 3.1M4 either.)

To get to the keyboard shortcuts, choose Window > Preferences from the main menu, which brings up the Preferences dialog. In 3.1M4, you can just type in “key” in the filter text box, which takes you to General>Keys. You then have to click the “Edit” button. In 3.0.1, you just navigate to Workbench>Keys.

Once you’re at the Keys preference, choose “Edit” from the Category drop-down. Then choose “Add Bookmark” from the Name drop-down. Then click in the Key Sequence > Name text box. Then hold down the keys you want to use for your keyboard shortcut. Being an Eclipse on Mac OS X user, I chose the available “Option-Cmd-B”. Then click the “Add” button. You should see the keyboard shortcut appear in both of the Assignments lists. (Note that “When: In Windows” always throws me off as a Mac user, but it just means not to use it within a dialog, which is OK since editors can only be in a window.)

Cool… now what? Well, it’d be nice if in Eclipse, we could:

1. Have bookmarks turned on by default, with the Bookmarks View showing, and a keyboard shortcut defined for all platforms for adding a bookmark.

2. Improve Bookmarks by adding an option to create a “quick” bookmark which didn’t need a description, like IntelliJ does. Allow quick navigation between bookmarks, at least in a file (previous/next bookmark in this file), like you can do with going to the next/previous error.

3. Allow sharing of bookmarks between team members. This might be overkill, since you can always tell people, go to this class and look at line #103, but it would be an interesting way to share code annotations.

Some tidbits:

1. If you hover over the blue bookmark marker in the left hand column of the editor, you’ll see a tooltip showing the description.

2. You can bookmark whole files by selecting the file in a view like the Package Explorer, then choosing Edit > Add Bookmark…

14 Replies to “Eclipse Tip: Use Bookmarks to track important places in your code”

  1. Thanks for the nice writeup.
    Is there a way I can have a hotkey to reach a bookmark? Like in Visual studio, you can do CTRL-F2 to traverse all the bookmarks..

  2. #2 of the “nice if …” section can somewhat be addressed by the prev/next annotation tool-bar buttons. They can be specified to move through bookmarks within a file by clicking on the arrow on the right side of the next/prev buttons and selecting the ‘bookmark’ checkbox.

    But, the plugin mentioned by Mort seems to address most of the other issues you mentioned, including this one.

  3. Good tips. Thanks!

    If you do as Hasan suggested, you can also move among bookmarks (within the same file) via Ctrl-. and Ctrl-, which are the default keyboard shortcuts for Next and Previous, where the toolbar dropdowns define the types of entities that are eligible to be the Next and Previous targets.


  4. Bookmarks are greyed out in Eclipse 3.4.1 in my context menu. So tried this plugin, then lost bookmarks in context menu entirely.

    Some strangeness here that I don’t understand, so reverted back.

    Navigation (breadcrumbs) is done nicely in Code::Blocks (c IDE). Maybe this might serve as good example for Eclipse to follow.

  5. I finally started adding bookmarks in Eclipse, but I couldn’t find where to look them up again. This post was very helpful (even years later :), thanks!


  6. thx a lot, when i use zend studio for php programing that ide has a excelent suport to bookmarks, but in eclipse i didn’t found it, now i can use bookmarks again!

  7. You can also add a bookmark by double clicking on the line number at the left side of the editor window.

Comments are closed.