What is the keyboard shortcut navigate back to the last cursor position in Visual Studio Code?
10 Answers
I am on Mac OS X, so I can't answer for Windows users:
I added a custom keymap entry and set it to Ctrl + ← + Ctrl + →, while the original default is Ctrl + - and Ctrl + Shift + - (which translates to Ctrl + ß and Ctrl + Shift+ß on my German keyboard).
One can simply modify it in the user keymap settings:
{ "key": "ctrl+left", "command": "workbench.action.navigateBack" },
{ "key": "ctrl+right", "command": "workbench.action.navigateForward" }
For the accepted answer I actually wonder :) Alt + ← / Alt + → jumps wordwise for me (which is kind of standard in all editors). Did they really do this mapping for the Windows version?
This will be different for each OS, based on the information in Key Bindings for Visual Studio Code.
Go Back: workbench.action.navigateBack
Go Forward: workbench.action.navigateForward
Linux
Go Back: Ctrl+Alt+-
Go Forward: Ctrl+Shift+-
Mac OS X
⌃- / ⌃⇧-
Windows
Alt+ ← / →
For macOS:
⌘ + U: Undo the last cursor operation
You can also try Ctrl + -.
BTW, all the shortcuts are in Keyboard shortcuts for macOS. This is really useful!
As an alternative to the keyboard shortcuts, there is an extension named "Back and Forward buttons" that adds the forward and back buttons to the status bar.
The answer for your question:
- Mac:
(Alt+←) For backward and (Alt+→) For forward navigation - Windows:
(Ctrl+-) For backward and (Ctrl+Shift+-) For forward navigation - Linux:
(Ctrl+Alt+-) For backward and (Ctrl+Shift+-) For forward navigation
You can find out the current key-bindings following this link
You can even edit the key-binding as per your preference.
With Visual Studio Code 1.43 (Q1 2020), those Alt+← / Alt+→, or Ctrl+- / Ctrl+Shift+- will also... preserve selection.
See issue 89699:
Benjamin Pasero (bpasero) adds:
going back/forward restores selections as they were.
Note that in order to get a history entry there needs to be at least 10 lines between the positions to consider the entry as new entry.
