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.
| Action | Windows / Linux | macOS |
| Go Back | Alt+Left Arrow | Ctrl+- |
| Go Forward | Alt+Right Arrow | Ctrl+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:
- Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS) - Type
Go Backand press Enter - For forward navigation, type
Go Forward
The internal command names are:
These are useful if you want to bind them to custom keyboard shortcuts.
Customizing the Shortcuts
To rebind these navigation commands to different keys:
- Open Keyboard Shortcuts with
Ctrl+K Ctrl+S(Windows/Linux) orCmd+K Cmd+S(macOS) - Search for
Go BackornavigateBack - Click the pencil icon next to the command
- Press your desired key combination
- Press Enter to confirm
You can also edit keybindings.json directly:
Some developers rebind these to mouse side buttons (back/forward) for faster navigation. VS Code recognizes mouse buttons in keybindings.
Navigate Back Within a Single File vs Across Files
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.
Navigate Within Current Editor Only
VS Code also provides commands that restrict navigation to the current file:
| Action | Command |
| Go Back in Current Editor | workbench.action.navigateBackInEditLocations |
| Go Forward in Current Editor | workbench.action.navigateForwardInEditLocations |
These are not bound to keys by default. To use them, add keybindings:
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:
Related navigation commands:
| Command | Shortcut (Win/Linux) | Shortcut (macOS) | What It Does |
| Go to Definition | F12 | F12 | Jump to where a symbol is defined |
| Peek Definition | Alt+F12 | Option+F12 | Show definition inline (no navigation needed) |
| Go to Type Definition | Ctrl+F12 | Cmd+F12 | Jump to the type's definition |
| Go to References | Shift+F12 | Shift+F12 | Show all references to a symbol |
| Go to Symbol in File | Ctrl+Shift+O | Cmd+Shift+O | Jump to a function/class in the current file |
| Go to Symbol in Workspace | Ctrl+T | Cmd+T | Jump to a function/class across all files |
| Go to Line | Ctrl+G | Ctrl+G | Jump to a specific line number |
Breadcrumbs Navigation
Enable breadcrumbs to see your current file path and symbol hierarchy at the top of the editor:
- Open Settings (
Ctrl+,/Cmd+,) - Search for "breadcrumbs"
- 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:
| Action | Default Shortcut |
| Toggle Bookmark | Ctrl+Alt+K |
| Jump to Next Bookmark | Ctrl+Alt+L |
| Jump to Previous Bookmark | Ctrl+Alt+J |
| List All Bookmarks | Command 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
| Action | Windows / Linux | macOS |
| Go Back | Alt+Left | Ctrl+- |
| Go Forward | Alt+Right | Ctrl+Shift+- |
| Go to Definition | F12 | F12 |
| Peek Definition | Alt+F12 | Option+F12 |
| Go to Symbol in File | Ctrl+Shift+O | Cmd+Shift+O |
| Go to Symbol in Workspace | Ctrl+T | Cmd+T |
| Go to Line | Ctrl+G | Ctrl+G |
| Go to File | Ctrl+P | Cmd+P |
| Switch Editor Tab | Ctrl+Tab | Ctrl+Tab |
| Navigate to Last Edit | Ctrl+K Ctrl+Q | Cmd+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+Leftmoves your cursor back to a previous position.Ctrl+Zundoes 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+Leftis 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 Arrowis 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) orCtrl+Shift+O(Go to Symbol) for direct jumps instead of navigating through history.
Summary
- Press
Alt+Left Arrow(Windows/Linux) orCtrl+-(macOS) to go back to your last cursor position. - Press
Alt+Right ArroworCtrl+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.navigateBackInEditLocationsfor file-scoped navigation (requires custom keybinding). - Use
Ctrl+K Ctrl+Q/Cmd+K Cmd+Qto jump to the last position where you actually edited text. - Install the Bookmarks extension for persistent, intentional position markers.

