The bookmark window is something of a red-headed step-child in Visual Studio. No real developer would be caught dead using bookmarks, right? I mean, it makes hoping around large projects so much easier. Therefore it must be cheating, right? I am here to tell you that it is o.k. to use bookmarks. In fact, you should be using bookmarks. Here's why.
Say you have a large project with a dozen or so solutions and hundreds of thousands of lines of code. Remembering where each and every function is or in what section a logical flow takes place, especially after that two week vacation, can be a little numbing. Further, you may be trying to enhance a large project, with areas you want to modify all over the place. You may also just want to easily jump back and forth between certain places in the code. Enter bookmarks.
Bookmarks are more than just place markers in your code; they can be named, categorized and organized. And they come with keyboard shortcuts and a tool window to make them oh so easy to use. Just use the keyboard commands to automatically jump around to specific areas in your code.
Unlike breakpoints, bookmarks can be set (Ctrl+K+K) on any line in the code file, even if the line is blank. You can also name your bookmarks to anything you like to make them easier to remember. Then you can use the keyboard to navigate through the shortcuts (Ctrl+K+P, Ctrl+K+N). Like breakpoints, however, you can enable or disable individual, groups of, or all bookmarks.
Folders allow you to group related bookmarks which allow you to find them easier. They also let you use the keyboard commands to navigate through bookmarks only within the current bookmark folder (Ctrl+Shift+N, Ctrl+Shift+P).
Bookmark Gotchas
There are a couple of gotchas with bookmarks.
- Bookmark folders cannot be nested, so no organizational hierarchy.
- The bookmark metadata is stored in the solution user options (.SUO) files, so they won't be automatically checked into source control (TFS, VSS, etc.) to be passed around to your team.
- You cannot change the icon for bookmarks to give them a more descriptive visual meaning.
Bookmark Keyboard Shortcuts
Lastly, here is a simple list of bookmark keyboard shortcuts, along with some helpful hints to help you remember them.
Description | Shortcut | Hint |
Go to Bookmark Tool Window | Ctrl+K+W | Window |
Toggle a bookmark on the current line | Ctrl+K+K | bookmarK |
New Folder (Bookmark Tool Window must have focus) | Ctrl+K+F | Folder |
Move the caret position to the previous bookmark. | Ctrl+K+P | Previous |
Move the caret position to the next bookmark. | Ctrl+K+N | Next |
Move the caret position to the previous bookmark in the current Folder. | Ctrl+Shift+K+P | Same folder Previous |
Move the caret position to the next bookmark in the current Folder. | Ctrl+Shift+K+N | Same folder Next |