Visual Studio Code
Coding Tips
Software Navigation
Programming Tools
Cursor Control

How can I navigate back to the last cursor position in Visual Studio Code?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

To navigate back to the last cursor position in VS Code, press Alt+Left Arrow on Windows/Linux or Ctrl+- on macOS. To go forward again, press Alt+Right Arrow or Ctrl+Shift+-. This works across files, meaning you can jump back to where you were even after switching to a different file.

The Primary Keyboard Shortcuts

VS Code maintains a history of every cursor position. Each time you click somewhere, use Go to Definition, or jump to a search result, that position is recorded.

ActionWindows / LinuxmacOS
Go BackAlt+Left ArrowCtrl+-
Go ForwardAlt+Right ArrowCtrl+Shift+-

These are the most important shortcuts to memorize. They save significant time when you are reading unfamiliar code and following function calls across multiple files.

How the Navigation History Works

VS Code records a new history entry when you:

  • Click to move your cursor to a different position
  • Use Go to Definition (F12)
  • Use Go to Symbol (Ctrl+Shift+O / Cmd+Shift+O)
  • Jump to a search result or error
  • Use Go to Line (Ctrl+G / Cmd+G)
  • Open a different file

Small cursor movements (arrow keys, scrolling without clicking) do not create new history entries. This prevents the history from being cluttered with every keystroke.

Using the Command Palette

If you forget the keyboard shortcut, use the Command Palette:

  1. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS)
  2. Type Go Back and press Enter
  3. For forward navigation, type Go Forward

The internal command names are:

 
workbench.action.navigateBack
workbench.action.navigateForward

These are useful if you want to bind them to custom keyboard shortcuts.

Customizing the Shortcuts

To rebind these navigation commands to different keys:

  1. Open Keyboard Shortcuts with Ctrl+K Ctrl+S (Windows/Linux) or Cmd+K Cmd+S (macOS)
  2. Search for Go Back or navigateBack
  3. Click the pencil icon next to the command
  4. Press your desired key combination
  5. Press Enter to confirm

You can also edit keybindings.json directly:

json
1[
2  {
3    "key": "ctrl+[",
4    "command": "workbench.action.navigateBack"
5  },
6  {
7    "key": "ctrl+]",
8    "command": "workbench.action.navigateForward"
9  }
10]

Some developers rebind these to mouse side buttons (back/forward) for faster navigation. VS Code recognizes mouse buttons in keybindings.

VS Code has two navigation modes that serve different purposes:

Standard Go Back/Forward (Across All Files)

The default Go Back / Go Forward commands navigate through all cursor positions across all files. If you jumped from app.js to utils.js via Go to Definition, pressing Go Back takes you back to app.js.

VS Code also provides commands that restrict navigation to the current file:

ActionCommand
Go Back in Current Editorworkbench.action.navigateBackInEditLocations
Go Forward in Current Editorworkbench.action.navigateForwardInEditLocations

These are not bound to keys by default. To use them, add keybindings:

json
1[
2  {
3    "key": "ctrl+alt+left",
4    "command": "workbench.action.navigateBackInEditLocations"
5  },
6  {
7    "key": "ctrl+alt+right",
8    "command": "workbench.action.navigateForwardInEditLocations"
9  }
10]

This is useful when you have been jumping around within a large file and want to retrace your steps without accidentally switching files.

Other Navigation Methods Worth Knowing

Go to Definition and Back

The most common reason to use Go Back is after using Go to Definition:

 
F12           -> Go to Definition
Alt+Left      -> Go Back (returns to where you pressed F12)

Related navigation commands:

CommandShortcut (Win/Linux)Shortcut (macOS)What It Does
Go to DefinitionF12F12Jump to where a symbol is defined
Peek DefinitionAlt+F12Option+F12Show definition inline (no navigation needed)
Go to Type DefinitionCtrl+F12Cmd+F12Jump to the type's definition
Go to ReferencesShift+F12Shift+F12Show all references to a symbol
Go to Symbol in FileCtrl+Shift+OCmd+Shift+OJump to a function/class in the current file
Go to Symbol in WorkspaceCtrl+TCmd+TJump to a function/class across all files
Go to LineCtrl+GCtrl+GJump to a specific line number

Enable breadcrumbs to see your current file path and symbol hierarchy at the top of the editor:

  1. Open Settings (Ctrl+, / Cmd+,)
  2. Search for "breadcrumbs"
  3. Enable Breadcrumbs: Enabled

Clicking any segment in the breadcrumb trail navigates to that location. You can also use Ctrl+Shift+. / Cmd+Shift+. to focus the breadcrumbs and navigate with arrow keys.

Bookmarks Extension

For positions you want to return to repeatedly, the Bookmarks extension (by Alessandro Fragnani) adds persistent markers:

ActionDefault Shortcut
Toggle BookmarkCtrl+Alt+K
Jump to Next BookmarkCtrl+Alt+L
Jump to Previous BookmarkCtrl+Alt+J
List All BookmarksCommand Palette: "Bookmarks: List"

Bookmarks persist across sessions and work across files. This is more intentional than cursor history: you mark the spots you know you will return to.

Quick Reference: All Navigation Shortcuts

ActionWindows / LinuxmacOS
Go BackAlt+LeftCtrl+-
Go ForwardAlt+RightCtrl+Shift+-
Go to DefinitionF12F12
Peek DefinitionAlt+F12Option+F12
Go to Symbol in FileCtrl+Shift+OCmd+Shift+O
Go to Symbol in WorkspaceCtrl+TCmd+T
Go to LineCtrl+GCtrl+G
Go to FileCtrl+PCmd+P
Switch Editor TabCtrl+TabCtrl+Tab
Navigate to Last EditCtrl+K Ctrl+QCmd+K Cmd+Q

The last entry, Navigate to Last Edit Location, is different from Go Back. It jumps to the position where you last made a text change, regardless of how many places you navigated to in between. Its command name is workbench.action.navigateToLastEditLocation.

Common Pitfalls

  • Confusing Go Back with Undo: Alt+Left moves your cursor back to a previous position. Ctrl+Z undoes your last text edit. They are completely different operations. Go Back does not change any text.
  • Go Back not working in the terminal: The keyboard shortcut Alt+Left is consumed by the integrated terminal for word-level cursor movement. You need to be in the editor for navigation shortcuts to work.
  • Conflict with browser-style navigation: On some Linux desktop environments, Alt+Left Arrow is used for window/workspace switching. Check your OS keyboard settings if the shortcut does not work in VS Code.
  • History not preserved after restart: VS Code clears the navigation history when you close and reopen the application. If you need persistent position memory, use the Bookmarks extension.
  • Too many history entries: If you click around frequently, the history gets long and Go Back requires many presses. Use Ctrl+P (Quick Open) or Ctrl+Shift+O (Go to Symbol) for direct jumps instead of navigating through history.

Summary

  • Press Alt+Left Arrow (Windows/Linux) or Ctrl+- (macOS) to go back to your last cursor position.
  • Press Alt+Right Arrow or Ctrl+Shift+- to go forward again.
  • These shortcuts work across files. Jumping back after Go to Definition (F12) is the most common use case.
  • Use workbench.action.navigateBackInEditLocations for file-scoped navigation (requires custom keybinding).
  • Use Ctrl+K Ctrl+Q / Cmd+K Cmd+Q to jump to the last position where you actually edited text.
  • Install the Bookmarks extension for persistent, intentional position markers.

Course illustration
Course illustration

All Rights Reserved.