What is the keyboard shortcut to navigate back to the last cursor position in Visual Studio Code?

- 9,619
- 8
- 37
- 59

- 15,513
- 17
- 54
- 69
-
2If it's the usual VS keymap I'm used to it's Ctrl - – Sami Kuhmonen Feb 16 '16 at 05:25
-
28In Visual Studio Code that shortcut corresponds to "Zoom Out: – kimsagro Feb 16 '16 at 05:33
-
6I think you mix up Mac OSX and Windows defaults here. CTR + - actually is the shortcut on OSX while CMD + - does zoom out there. – OderWat Feb 21 '16 at 19:55
-
3Use Visual Studio Keymap extension - https://marketplace.visualstudio.com/items?itemName=ms-vscode.vs-keybindings – George Paoli Mar 09 '18 at 19:03
-
3As of VS Code 1.28, you can go to the last *edit* location using `Ctrl+K Ctrl+Q` - https://code.visualstudio.com/updates/v1_28#_navigate-to-last-edit-location – sudormrfbin Oct 09 '18 at 00:35
-
@kimsagro Please delete or edit your comment. It is not "Zoom Out" but rather "Go Forward" and "Go Back". – Andrew Sep 23 '20 at 19:57
-
@Andrew The default keys that View: Zoom In and View: Zoom Out are bound to are `CTRL`-`=` and `CTRL`-`-`, respectively. The `=` key is the unshifted `+`. `+` and `-` are the keys on the numeric row of the regular keyboard, not the keys on numeric keypad, which are referred to as `NumPad_Add` and `NumPad_Subtract`, defying conventional names as MS often does. – Suncat2000 Apr 15 '22 at 13:49
16 Answers
The keyboard shortcut commands are Go Forward and Go Back.
On Windows:
Alt + ← ... navigate back
Alt + → ... navigate forward
On Mac:
Ctrl + - ... navigate back
Ctrl + Shift + - ... navigate forward
On Ubuntu Linux:
Ctrl + Alt + - ... navigate back
Ctrl + Shift + - ... navigate forward
-
187I wonder why Microsoft decided to have different hot keys than regular visual studio. This is very annoying switching having to switch back and forth. – RayLoveless Dec 23 '17 at 04:54
-
36Can you do this with your mouse? In other IDEs the back gesture/button navigates back as well. – rynop Feb 28 '18 at 14:56
-
@RayLoveless It's maybe hard to switch back and forth, but it's super easy just to switch forth. Maybe they cherry-pick it to VS. – Lukas Salich Mar 23 '18 at 15:13
-
3Kind of an annoying binding for windows, unfortunately :( Would've been good to have the same as visual studio. – Chris Owens May 18 '18 at 07:24
-
2
-
2The left Alt+arrows didn't work for me on Windows (it did something similar to Ctrl+arrows), only the **right** Alt+arrows does what's expected. Who knows what weird ThinkPad keyboard magic is causing that. – ewbi Dec 07 '18 at 01:21
-
10@RayLoveless VS Code is made by Microsoft so the Windows shortcut is the default. Alt+← is a system shortcut on linux and mac so they had to change it. – Lenny Jan 21 '20 at 21:27
-
1
-
2Not working on Ubuntu. Vscode seems like a half-baked IDE. It's being a pain even to get some basic functionality to work. – Gayan Weerakutti May 03 '20 at 07:42
-
1I'd like to get the Windows behaviour on Linux. Is there a fairly easy way to change that? – andyczerwonka Jul 24 '20 at 15:30
-
@RayLoveless Are you sure for Linux? I use Ubuntu Linux Mint and Alt+Arrow is for me a way to navigate to the previous and next page on Nemo and Firefox. – Jean Paul Oct 22 '20 at 15:49
-
4searching `workbench.action.navigateBack` & `workbench.action.navigateForward` under **Preferences > Keyboard Shortcuts** worked for me, since I had an extension changing the default behaviour – Alex Jun 01 '21 at 12:30
-
and in 2021 not working in code on debian testing. So frustrating. Tethered to a mouse. set navigate forward and back to alt+left/right and it doesnt work. And no, it isnt a system keybinding. – RichieHH Oct 03 '21 at 07:28
-
I like the Windows shortcuts here, but I'm on Linux. Thankfully, it is easily changeable via Ctrl + Alt + P then "Preferences: Open Keyboard Shortcuts." – Gabriel Staples Oct 15 '21 at 02:22
-
there is a plugin for this, (Code Navigation ) https://marketplace.visualstudio.com/items?itemName=vikas.code-navigation , it is very useful. I don't understand why such a basic feature not added to the IDE. – Adem Dec 05 '21 at 15:46
-
-
I changed mine to CTRL+ALT+- and CTRL+ALT++, so at least they would be symmetrical. – toddmo Nov 14 '22 at 16:17
-
-
@rynop There is also a default mapping to the next / previous thumb buttons on the mouse. These shortcuts are very useful when working on a laptop touchpad or a mouse without side buttons. – ThaJay Jan 19 '23 at 08:25
-
Where is difference between **Back** / **Forward** and **Last Edit Location**? – Xintrea May 23 '23 at 14:09
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?

- 30,738
- 21
- 105
- 131

- 5,379
- 3
- 29
- 31
-
16`Ctrl+Left` and `Ctrl+Right` are reserved for switching between full-screens, aren't they? – duong_dajgja Jul 19 '17 at 02:51
-
4@duong_dajgja I have that on Ctrl+Option+Command Left / Right. Most people will usually just use the three finger wipe on their Trackpad. I am not sure whats the "original" default in a fresh installed OS X Sierra though. At least there is nothing reserved in OS X. You can easily change that in the system preferences "keyboard -> mission control". – OderWat Jul 19 '17 at 21:40
-
6Use this to make those changes https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization – Average Joe Nov 06 '17 at 09:11
-
1Is there a way I can assign my mouse forward and backward buttons to navigate? – Firzok Nadeem Feb 23 '20 at 17:42
-
As @duong_dajgja pointed out this key combination is reserved. I used `ctrl+shift+left` instead. – James Webb Dec 20 '21 at 12:47
-
1Great answer. Also you can find it through *File → Preferences → Keyboard Shortcuts* then searching *Go Back* and *Go Forward* – Benyamin Jafari Apr 09 '22 at 16:19
This will be different for each OS, based on the information in Key Bindings for Visual Studio Code.
Workbench configuration:
Go Back: workbench.action.navigateBack
Go Forward: workbench.action.navigateForward
Linux:
Go Back: Ctrl+Alt+-
Go Forward: Ctrl+Shift+-
Mac OS X:
Go Back: Ctrl + -
Go Forward: Ctrl + Shift (⇧) + -
Windows:
Go Back: Alt + ⬅️
Go Forward: Alt + ➡️

- 3,910
- 1
- 20
- 29
-
4I'm using linux and the default keymap didn't work. I modified to Alt+Left and worked like a charm. – greuze May 24 '17 at 09:17
-
3
-
2`File/preferences/Keyboard shortcut [Ctrl-K Ctrl-S]` then search "workbench.action.navigateBack". Had to set it on Linux. – pdem Apr 12 '23 at 12:54
To answer for your question, for:
- Windows use Alt+← for backward, and Alt+→ for forward navigation.
- macOS use Ctrl+- for backward, and Ctrl+Shift+- for forward navigation.
- Linux use Ctrl+Alt+- for backward, and Ctrl+Shift+- for forward navigation.
You can find the current key-bindings in "Keyboard Shortcuts editor."
You can even edit the key-binding as per your preference.

- 158,662
- 42
- 215
- 303

- 2,123
- 1
- 18
- 23
There is an extension available named Code-Navigation for all the platforms. As an alternative to the keyboard shortcuts it adds buttons to the left side of the status bar.

- 1,593
- 2
- 18
- 37
-
4
-
1
-
1Apparently now this is built into VSCode: https://stackoverflow.com/a/75892641/399435 – Karthic Raghupathi Jul 08 '23 at 23:33
-
To set your own keyboard shortcuts (even if that particular keyboard-combo is already taken) you can go to Code > Preferences > Keyboard Shortcuts
and set them up there.
- Open Settings:
Code > Preferences > Keyboard Shortcuts
- Find
Go Forward
andGo Back
and set them to whatever you like. - If a key shortcut is double-assigned VSCode will tell you, and you can click-in and change/remove the other ones. eg. by shortcuts were already assigned to indent-in and indent-out.
eg. our main tool is Android Studio on a mac which uses cmd+[
and cmd+]
for forward and backward). This is especially powerful with a cmd+click
for drilling into functions. (so you can follow your code as if it was an Ariadne's thread in a Minotaur labyrinth. Does help! ( so you jump around the code, diving in and out of functions, and back between files.

- 2,348
- 23
- 17
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!

- 30,738
- 21
- 105
- 131

- 674
- 8
- 24
-
1Thanks so much for this answer! While all the others actually tell you how to navigate back and forth through different files, I was interested in navigating the cursor history. You could add (although it's kinda obvious) that there's the redo cursor operation to go with it. – panepeter Apr 08 '21 at 15:06
vscode v1.65 is adding a number of new commands for navigating to the last/next edit location or the last/next cursor location.
An edit location
means there was an actual edit, whereas a cursor location
means that you visited that location but may not necessarily have made an edit there.
By default, editor navigation locations are added whenever you navigate across editors but also when navigating within editors (for example, when switching notebook cells or changing selection in text editors). If you feel that too many locations are being recorded, new commands have been added that reduce locations to either:
- Navigation locations (for example when using Go to Definition)
- Edit locations (whenever an editor is changed, for example when typing in a text editor)
Cursor locations:
Go Forward in Navigation Locations
"workbench.action.navigateForwardInNavigationLocations"
Go Back in Navigation Locations
"workbench.action.navigateBackInNavigationLocations"
Go to Last Navigation Location
// acts like a toggle between current and last cursor location
"workbench.action.navigateToLastNavigationLocation"
Go Previous in Navigation Locations
"workbench.action.navigatePreviousInNavigationLocations"
Edit locations:
Go Forward in Edit Locations
"workbench.action.navigateForwardInEditLocations"
Go Back in Edit Locations
"workbench.action.navigateBackInEditLocations"
Go Previous in Edit Locations
"workbench.action.navigatePreviousInEditLocations"
Go to Last Edit Location
// acts like a toggle between current and last edit location
"workbench.action.navigateToLastEditLocation"
Associated context keys have been added to make assigning keybindings more powerful:
canNavigateBackInNavigationLocations
: Whether it is possible to go back in navigation locationscanNavigateForwardInNavigationLocations
: Whether it is possible to go forward in navigation locationscanNavigateToLastNavigationLocation
: Whether it is possible to go to the last navigation locationcanNavigateBackInEditLocations
: Whether it is possible to go back in edit locationscanNavigateForwardInEditLocations
: Whether it is possible to go forward in edit locationscanNavigateToLastEditLocation
: Whether it is possible to go to the last edit location

- 143,421
- 24
- 428
- 436
Use Alt + ← / →
You can find all shortcuts in Key Bindings for Visual Studio Code.

- 30,738
- 21
- 105
- 131

- 2,381
- 1
- 17
- 17
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.

- 30,738
- 21
- 105
- 131

- 109
- 1
- 6
You can go to menu File → Preferences → Keyboard Shortcuts. Once you are there, you can search for navigate. Then, you will see all shortcuts set for your Visual Studio Code environment related to navigation. In my case, it was only Alt + - to get my cursor back.

- 30,738
- 21
- 105
- 131

- 1,509
- 15
- 17
-
`Ctrl` + `Alt` + `-` on Linux (Visual Studio Code 1.54.3 on [Ubuntu MATE 20.04](https://en.wikipedia.org/wiki/Ubuntu_MATE#Releases) (Focal Fossa)). – Peter Mortensen Apr 17 '21 at 14:19
While the accepted answer is correct, anyone using the Vim extension for VS Code may be frustrated by the fact that navigating backwards takes you through every single cursor movement you've made. This prevents "Go back" from working well for use cases like:
- Go to Definition
- Poke around at the definition for a while (i.e., move the cursor around)
- Go Back to where you were in step 1.
With the Vim extension installed, you'll be stuck doing "Go Back" for every cursor movement you've made (and for me, that's enough to make it almost useless!).
Fortunately, the Vim extension implements jumplists well, so after using VS Code to jump to a new position (i.e., "Go to definition"), you can simply do CTRL+O to go back to the previous jump location.

- 12,306
- 4
- 45
- 62
Last Edit Position v. Last Navigation Position
Go To Last Edit Position:
Ctrl+k Ctrl+q
This was mentioned in sudormfbin's comment but not listed as an answer. This is what I want to do 99% of the time when I think "where was I now?". It is the easiest quickest way to get back to your last position without taking your fingers off keyboard to use the arrow keys and without installing extensions, etc.
Navigate Recent Cursor Positions:
ALT+ ← Back
ALT+→ Forward
Most of the other posted solutions refer to this - moving between "Navigation Locations", i.e., navigating between editor tabs OR within an editor (e.g., you move the cursor on one line, then click on a line 20 spaces above).
For navigating between editor tabs, instead of the above you can do Ctrl+Tab as it will sort all of the tabs in most recent order so you have option to go to others or just release and go back to the last used one. Also without taking fingers off keyboard.

- 695
- 7
- 14
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.

- 30,738
- 21
- 105
- 131

- 1,262,500
- 529
- 4,410
- 5,250
There are several ways to go back and options to go back in vs code.
To change any of the following things, go to command pannel by pressing ctrl
+ p
and then after typing a >
, type what config you need to change:
Then all you need to do is click on the Settings icon (as pointed by 2 in the image) and change the key binding to whatever you want.
Different options you have for going back:
- Go to the Last Edit Location
- Cursor Undo
(meaning: go to last cursor location)
- Cursor Redo
(Opposite of above)

- 3,119
- 3
- 29
- 34