Go Back to Previous Cursor Position in VS Code
Navigating back to your previous cursor position in Visual Studio Code (VS Code) is a crucial shortcut for maintaining your coding flow and efficiency. This article provides a quick guide on the default keyboard shortcuts for navigating backward and forward through your cursor history on Windows, macOS, and Linux, as well as how to customize these keybindings to fit your workflow.
Default Keyboard Shortcuts
VS Code automatically tracks your cursor history as you edit and jump between different files or lines of code. You can quickly leap backward and forward through this history using the following default keyboard shortcuts:
- Windows:
- Go Back:
Alt + Left Arrow - Go Forward:
Alt + Right Arrow
- Go Back:
- macOS:
- Go Back:
Ctrl + -(Control + Minus) - Go Forward:
Ctrl + Shift + -
- Go Back:
- Linux:
- Go Back:
Ctrl + Alt + - - Go Forward:
Ctrl + Shift + -
- Go Back:
Navigating via the Command Palette
If you prefer using the Command Palette, or if you want to verify the commands, you can navigate your cursor history using these steps:
- Open the Command Palette using
Ctrl + Shift + P(Windows/Linux) orCmd + Shift + P(macOS). - Type Go Back or Go Forward.
- Press
Enterto execute the selected command.
How to Customize the Navigation Shortcuts
If the default shortcuts conflict with your operating system or other extensions, you can change them to your preferred key combinations:
- Open the Keyboard Shortcuts editor by pressing
Ctrl + K Ctrl + S(Windows/Linux) orCmd + K Cmd + S(macOS). - In the search bar at the top, type
workbench.action.navigateBackto find the Go Back command, orworkbench.action.navigateForwardfor the Go Forward command. - Double-click the command you want to change.
- Press the new key combination you wish to assign on your keyboard,
and then press
Enterto save it.