ChatGPT解决这个技术问题 Extra ChatGPT

Are there bookmarks in Visual Studio Code?

How can I set bookmarks in Visual Studio Code? I can't find any keyboard shortcuts.

Or is there anything else that I can use instead?

Looks like Bookmarks is a little more powerful than Numbered Bookmarks. It supports labels, which could do whatever numbering scheme you could ever desire. Also, Numbered Bookmarks appears to be limited to 0-9.
Bookmarks extension: Ctrl+K+S (or Ctrl+Shift+P to open Keyboard Shortcuts) and search for Bookmarks to assign/change hotkeys. Also nice: it adds a new tab to the left side so you can view your bookmarks. They persist between sessions.
you can press ctrl+- (go back) or ctrl+shift+- (go forward) to move cursor to where it was, works across files. sort of like bookmarks
for me ctrl+- and ctrl+shift+- reduce the window zoom level (zoom out). ctrl+k ctrl+q jumps to the last edit location.
It's Ctrl+Alt+- and Ctrl+Shift+- for me. These commands are in the "Go" menu.

G
Gama11

Yes, via extensions. Try Bookmarks extension on marketplace.visualstudio.com

Hit Ctrl+Shift+P and type the install extensions and press enter, then type Bookmark and press enter.

https://i.stack.imgur.com/opkdv.png

Next you may wish to customize what keys are used to make a bookmark and move to it. For that see this question.


Bookmarks now navigate through all files. Numbered bookmarks still miss this important feature.
Are you asking for it to NOT navigate through all files? If I remember correctly the Bookmarks extension above is not numbered, and the reason I don't want to use Numbered bookmarks is it's just another mental bit of trivia that distracts me. I just want un-numbered ones. You also? Or you are different?
Yes they do. You can determine maximum 10 bookmarks. But that is enough, for your work context.
"Next you may wish to customize what keys are used to make a bookmark and move to it." – It would be great if the default shortcuts would be within the readme file. Nothing mentioned, thus useless. – Edit: Found out how to set the bookmark: CTRL+ALT+K. CTRL+ALT+J to jump to it.
Very embarrassing, a most famous code editor with no native bookmark support.
A
Andreas

You need to do this via an extension as of the version 1.8.1.

Go to View → Extensions. This will open Extensions Panel. Type bookmark to list all related extensions. Install

I personally like "Numbered Bookmarks" - it is pretty simple and powerful.

Go to the line you need to create a bookmark.

Click Ctrl + Shift + [some number]

Ex: Ctrl + Shift + 2

Now you can jump to this line from anywhere by pressing Ctrl + number

Ex: Ctrl + 2


One drawback with "Numbered bookmarks" for some use cases is that the bookmarks are per file. Meaning you can't jump to another file using this extension. A feature request to implement this: github.com/alefragnani/vscode-numbered-bookmarks/issues/6
@Green They do work! Please follow the instructions in the answer.
Numbered Bookmarks 0.11.0 do supports navigation across the files. In user setting add the line - "numberedBookmarks.navigateThroughAllFiles": "allowDuplicates"
best thing ever
Note that there are three settings for navigateThroughAllFiles. The "allowDuplicates" option will allow multiple bookmarks of the same number across different files, from what I understand. The "replace" option works much better for me - one set across all files. Nice.
M
Martin Brown

Visual Studio Code currently does not support bookmarks natively. Please add this as feature request to our Git Hub issue list (https://github.com/Microsoft/vscode).

In the meantime there are some ways to navigate around the code based on your navigation history. You can Ctrl+Tab to quickly jump to previously opened files. You can also navigate within your code based on cursor positions using Goto | Back and Goto | Forward.


The uservoice request became a request for an extension. It is now marked as "done". See my answer for how to install the extension and then set what keyboard shortcuts are used for it.
I
Ian Boyd

Both VS Code extensions can be used:

'Bookmarks' 'Numbered Bookmarks'

Personally, I'm suggesting: Numbered Bookmarks, with 'navigate through all files' option:

ctrl + Shift + P in VS Code In newly open field, type: Open User Settings Paste this key/value: "numberedBookmarks.navigateThroughAllFiles": "allowDuplicates" (allow duplicates of bookmarks), Or, paste this key/value: "numberedBookmarks.navigateThroughAllFiles": "replace"

NOTE

Either way, be careful with shortcuts (Ctrl+1, Ctrl+Shift+1,..) that are already assigned.

Personally, mine were in 2 conflicts, with:

VS Code shortcuts, that already exists, Ditto clipboard (I've got paste on each call of bookmark)


I'm using Numbered Bookmarks, but on Mac the short cut Shift + Cmd + 3 and Shift + Cmd + 4 are already assigned for taking a screen shot.
@user1941537 yes I am facing this issue also. Any solution for this ?
Can i somehow give a name to the bookmark and see bookmarks on some list?
C
Cees Timmerman

The bookmarks extension mentioned in the accepted answer conflicts with toggling breakpoints via the margin.

https://i.stack.imgur.com/ChvcP.png


To work around toggling breakpoints on a bookmarked line, just press F9 (toggles breakpoint).
T
Tryer

If you are using vscodevim extension, then you can harness the power of vim keyboard moves. When you are on a line that you would like to bookmark, in normal mode, you can type:

m {a-z A-Z} for a possible 52 bookmarks within a file. Small letter alphabets are for bookmarks within a single file. Capital letters preserve their marks across files.

To navigate to a bookmark from within any file, you then need to hit ' {a-z A-Z}. I don't think these bookmarks stay across different VSCode sessions though.

More vim shortcuts here.


a
ajaysinghdav10d

Under the general heading of 'editors always forget to document getting out…' to toggle go to another line and press the combination ctrl+shift+'N' to erase the current bookmark do the same on marked line…


Sorry, but this is misleading, ctrl+shift+n creates a new document.. As other people said, there is only possibility with installing extension.