113

In various projects there are certain parts I will keep jumping to. Is there a way to effectively "bookmark" these parts, so I can quickly jump back to a certain line in a certain file (or a certain method)?

I keep getting lost navigating the solution or doing a "find in whole project/solution".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
joshcomley
  • 28,099
  • 24
  • 107
  • 147

11 Answers11

184

In Visual Studio, you can set Bookmarks in the code.

To jump between Bookmarks:

Ctrl + K + N (for next)

and

Ctrl + K + P (for previous)

To toggle a Bookmark on/off for a line:

Ctrl + K + K

Owain Evans
  • 374
  • 1
  • 3
  • 12
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
  • 2
    That's super - is there a way to label them and look them up? Or are they designed as a temporary thing? Also, is there a way to jump between breakpoints? – joshcomley May 29 '09 at 14:12
  • 1
    Unfortunately, you can't label markers. There might be a plug-in that does it, but I'm not sure. I'm unaware of a keyboard shortcut to jump between breakpoints. – Jordan Parmer May 29 '09 at 14:23
  • 15
    At the bookmark window you can change the Bookmarks names. – Pedro77 Jan 14 '15 at 11:31
  • 7
    You ***can*** label bookmarks (in the bookmark window). Ctrl + K + W to open the window. Right click on a bookmark and chose *"Rename"*. – Peter Mortensen Mar 26 '17 at 10:54
  • tnx its helpfull – Alireza Jan 14 '18 at 08:54
  • What about Visual Studio Code? – F.H. Feb 20 '19 at 10:06
  • i think mine is not working properly... CTRL + K + K doesnt give me anything at all... – gumuruh May 06 '20 at 06:58
  • My answer here is 11 years old now. Good chance it has been updated. Are you using VS Code? – Jordan Parmer May 06 '20 at 18:17
  • 1
    The problem with "standard" bookmarks, as far as I know, is that they are fixed to the line they were initially created. And as soon as you modify the file, your bookmark will not be bookmarking the same place you originally intended it to bookmark (usually a method or block of code). And since you usually want to use them precisely in files you are actively modifying, this make them pretty impractical. Does anybody know how to bookmark a method or piece of code?? – Rodrigo Jun 04 '20 at 09:05
  • @Rodrigo, for me in VS2019, if I place a bookmark and then insert a line above the bookmark, the bookmark is shifted downwards. – Joma Jun 16 '21 at 21:05
  • VS2019 Ctrl-K-P doesn't work, only Ctrl-K-N. – Rekshino Jul 20 '21 at 16:35
  • In mine it's `Ctrl`+`B`,`P` or `Ctrl`+`B`,`N` – xr280xr Nov 05 '21 at 14:37
22

Yes, press the hotkey combination Ctrl + K + K (that's Ctrl and K, followed by another K) to toggle a bookmark.

Then you can do Ctrl + K + N for the next bookmark and Ctrl + K + P for the previous bookmark.

It works like a charm!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Makach
  • 7,435
  • 6
  • 28
  • 37
  • Slightly off topic, but is there a correct notation for describing sequences of keyboard presses like the ones you have above? I would expect that a more intuitive representation could be done like this: Ctrl + (K, K). What do you think? – Will Ediger Oct 16 '15 at 16:51
10

With ReSharper, there's a more flexible way of making bookmarks and navigating to them.

You can press Ctrl + Shift + Number for example 3. And then refer to that by Ctrl + 3.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ali Seyedi
  • 1,758
  • 1
  • 19
  • 24
  • 1
    Aaahhh! I was wondering how that worked, considering I was trying to get the font size back to normal (CTRL + 0 like a browser) and it kept saying "Could not go to bookmark #0". (Zero doesn't work as I also found out after reading this. Hmm, although CTRL + ` brings up that option!) – SharpC Feb 18 '20 at 09:06
9

I could use the TODO feature, adding my own custom prefix of "BOOKMARK", or "BM" if I'm going to be lazy.

MSDN Documentation For Custom Tags

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
joshcomley
  • 28,099
  • 24
  • 107
  • 147
  • 9
    use built-in bookmarks instead. it will keep you from unnecessary code modification. – Andrey May 29 '09 at 13:53
  • 8
    the good thing using TODO feature is that your 'bookmarks' move with your code when you edit, cut, paste... Using 'real bookmarks' you get them always moved out of the original place you put them (at least in 2013 pro) – Ivan Ferrer Villa Jul 11 '15 at 02:38
  • 1
    Totally agree this is the best solution!! Go to Tools/Options/Environment/Task List and add a new tag. I wanted to use the phrase 'MARK' but this word is too common, so I'm using 'BOOKMARK' set as low priority. Whenever I want to create one I just type "//BOOKMARK: this is a bookmark", and that's it done, simple! To view them just open the Task List window and sort by priority or description and scroll down. This is hugely better as they are 'pinned' with the actualy code and don't drift and can be shared with over developers, unlike standard bookmarks. – userSteve Jun 14 '16 at 08:48
  • This is the best way to bookmark code in Visual Studio. In Visual Studio 2010 at least if you bookmark a line or add a task list shortcut, then if you move your code a few lines, save your code, then close and open Visual Studio. the bookmarks and task list shortcuts will be on the wrong lines. But this method does not have such problems. – Ghos3t Sep 08 '17 at 09:31
6

Recent versions of Visual Studio (at least from Visual Studio 2010) have all the comfort for bookmarking. Here is my workflow:

First, you should remember two shortcuts, Show Bookmark Window and Toggle Bookmark. In my setup it is Ctrl + W + B and Ctrl + B + T respectively.

Second, set the Bookmark window to autohide. That step was important for me to finally make bookmarking easy and comforting.

That's how I use bookmarks:

When I am in a position of interest, I Toggle Bookmark and Show Bookmark Window, then press F2 and rename entry — using reasonable names is very helpful for easy navigation.

When I want to get to another position of interest, I Show Bookmark Window, navigate to needed entry, press enter, and voila, I am there.

For me, discovering autohide of a bookmark window was cricial: it allows to quickly get the full view of points of interest, and then it leaves and returns focus to the editor.

Stas Bushuev
  • 318
  • 3
  • 9
6

There is also shortcuts: Ctrl-K, Ctrl-H - sets or removes a shortcut in the tasklist to the current line.

List of all the shortcuts you can see in Task List window. To open it click View - Task List in menu or press Ctrl-\, T. In that window you can select User Tasks, Shortcuts or Comments (not in VS2015).

Visual Studio 2015 bookmarks and shortcuts

Vladislav
  • 1,696
  • 27
  • 37
2

Visual Studio Bookmarks are a great productivity boost. Click on "View, Bookmarks" (Ctrl K, Ctrl W), you can group your Bookmarks by category - just create a folder, and drag related bookmarks into the folder. They can all be enabled/disabled with one click.

This comes in real handy if you are working on two or more sets of problems concurrently, and you don't want to be schlepping through Enhancement A's book marks while focusing on Bug B. Simply group each problem's set of bookmarks in their respective folders, and you can (de)activate them with one click.

Also, if there are certain places where you have to go back often, simply create a disabled bookmark, and jump directly there through the Bookmark window.

Here is an example:

enter image description here Visual Studio named bookmarks

Pierre
  • 4,114
  • 2
  • 34
  • 39
2

I too was looking for a better solution to this, having moved from the Delphi 7 IDE to Visual Studio 2010 recently. This comment wonders whether there might be a plug-in that does this and that directed me to the Extension Manager & a search for Bookmark brought up DPack.

I think this gives the OP exactly what he is looking for, particularly when taking this comment of his into account.

Note: Once installed I had to edit the keyboard mappings via Tools | Options | Environment | Keyboard. I put DPack into the Show commands containing edit box, and then scrolled down to find the GoToBookmark[x] and ToggleBookmark[x] that were not working for me and assigned them using the Press shortcut keys edit box. (Make a note of what the "Shortcut [is] currently being used by" before you do this, though; I wouldn't want you to overwrite a function that you don't realize you use extensively!)

Community
  • 1
  • 1
lukkea
  • 3,606
  • 2
  • 37
  • 51
1

Go to View | Toolbars and check the Text Editor toolbar so it shows up. It has toolbar buttons to Toggle (create/delete) a bookmark on the current line Ctrl-B, T, as well as navigation to the next/prev bookmark, where the navigation is scoped to the solution, folder, or document, depending on which button you use.

Once you have a bookmark created, go to View | Other Windows and select the Bookmark Window (or just press Ctrl-W, B). That will display the list of all the bookmarks. You can double-click any bookmark to jump to it, or use the toolbar button in the Bookmark window for prev/next.

You can also name/rename your bookmarks in the Bookmark window. Right-click on the name and choose rename, or select the name and click it again to enter in to the edit mode.

0

You can install extension: VSBookmarks

Provides up to nine enumerated bookmarks for every text editor tab. All of them are accessible by shortcuts or via a context-menu (right-click and see for VSBookmark submenu).

Ctrl-Shift-[1..9] - set, change or remove a bookmark (you will see an appropriate digit on the left margin of the editor area); Ctrl-[1..9] - go to a previously set bookmark.

enter image description here

-1

In Visual Studio 2017 it's

  • Toggle: Ctrl + B, T
  • Enable: Ctrl + B, E
  • Delete all: Ctrl + B, C
BanksySan
  • 27,362
  • 33
  • 117
  • 216