英文:
How can i save my current cursor position in Visual Studio Code (VS Code), so that i can come back to it quickly
问题
我想要保存当前光标位置,移动到其他行(在同一个文件中),进行一些编辑,然后跳回到原始光标位置以继续编码。
比如我在第50行,意识到需要在第5行添加一个标题/库文件。我想要保存我的位置,这样在第5行做完修改后可以跳回来。我该怎么做?
我已经研究了光标导航快捷键,但它们都是通过跟踪光标之前所在的每个位置来移动光标,这很耗时且令人困惑。相反,我希望能够一次性跳回到保存的位置。
英文:
I want to save my current cursor position, move to some other line (in the same file), do some editing and jump back to the original cursor position to continue coding.
Lets say i am in line 50 and realise i need to add a header/library file at line 5. I want save my position here so that i can jump back after making my changes at line 5. How can i do this?
I have looked into cursor navigation shortcuts but they all move cursor by tracing every position cursor was in, and its time consuming and confusing, instead i want to jump back to saved position in one shot.
答案1
得分: 2
没有内置命令可以做到这一点。 返回
/ 前进
导航命令不允许您 保存 特定位置。
相反,您应该依赖于扩展,比如我的 Bookmarks 扩展。
还有许多类似的扩展,您可以在此搜索中查看: https://marketplace.visualstudio.com/search?term=bookmarks&target=VSCode&category=All%20categories&sortBy=Relevance。您可以看一些,然后试用一个最适合您需求的扩展。
希望对您有所帮助。
英文:
There is no built-in command for that. The Go Back
/ Go Forward
navigation commands doesn't allows you to save specific locations.
Instead, you should rely on extensions, like my Bookmarks extensions.
There is a bunch of other similar extensions, as you can see on this search https://marketplace.visualstudio.com/search?term=bookmarks&target=VSCode&category=All%20categories&sortBy=Relevance. You should take a look at some, and try out the one that better fit our needs.
Hope this helps
答案2
得分: 2
你可以使用selection anchor。没有默认的“转到选择锚点”键绑定,所以你需要自己添加一个。
英文:
You could use the selection anchor. There is no default keybinding for "Go to Selection Anchor" so you'd have to add one yourself.
答案3
得分: 1
感谢@scottfrazer提供了有关选择锚点的建议。
感谢@alefragnani提出了有关扩展的建议。
根据这些答案,我使用multi command扩展编写了一个键绑定。
安装multi command扩展后,在keybindings.json中添加以下代码:
[
{
"key": "ctrl+alt+`",
"command": "extension.multiCommand.execute",
"when": "!selectionAnchorSet",
"args": {
"sequence": [
"editor.action.setSelectionAnchor",
]
}
},
{
"key": "ctrl+alt+`",
"command": "extension.multiCommand.execute",
"when": "selectionAnchorSet",
"args": {
"sequence": [
"editor.action.goToSelectionAnchor",
"editor.action.cancelSelectionAnchor",
]
}
}
]
上述代码将创建一个"ctrl+alt+`"(Ctrl + Alt + BackTick)的键绑定。
按下时,会执行以下操作:
- 在光标位置创建一个选择锚点。
- 如果已经存在锚点,将光标移到该位置并删除该位置的锚点。
英文:
Thanks @scottfrazer for the suggesting selection anchor.
Thanks @alefragnani for suggesting extensions.
Based on these answers, i wrote a keybinding using multi command extension,
After installing the multi command extension,
Add the following snippets in the keybindings.json,
[
{
"key": "ctrl+alt+`",
"command": "extension.multiCommand.execute",
"when": "!selectionAnchorSet",
"args": {
"sequence": [
"editor.action.setSelectionAnchor",
]
}
},
{
"key": "ctrl+alt+`",
"command": "extension.multiCommand.execute",
"when": "selectionAnchorSet",
"args": {
"sequence": [
"editor.action.goToSelectionAnchor",
"editor.action.cancelSelectionAnchor",
]
}
},
]
Above snippet will create a key binding for "ctrl+alt+`" (Ctrl + Alt + BackTick).
When pressed,
- Creates a selection anchor at cursor position
- If an anchor already exists, Move to that cursor position and deletes that anchor at that position.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论