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:

If you prefer using the Command Palette, or if you want to verify the commands, you can navigate your cursor history using these steps:

  1. Open the Command Palette using Ctrl + Shift + P (Windows/Linux) or Cmd + Shift + P (macOS).
  2. Type Go Back or Go Forward.
  3. Press Enter to 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:

  1. Open the Keyboard Shortcuts editor by pressing Ctrl + K Ctrl + S (Windows/Linux) or Cmd + K Cmd + S (macOS).
  2. In the search bar at the top, type workbench.action.navigateBack to find the Go Back command, or workbench.action.navigateForward for the Go Forward command.
  3. Double-click the command you want to change.
  4. Press the new key combination you wish to assign on your keyboard, and then press Enter to save it.