1392

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

0Valt
10.5k9 gold badges41 silver badges65 bronze badges
asked Feb 16, 2016 at 5:20
9
  • 3
    If it's the usual VS keymap I'm used to it's Ctrl - Commented Feb 16, 2016 at 5:25
  • 33
    In Visual Studio Code that shortcut corresponds to "Zoom Out: Commented Feb 16, 2016 at 5:33
  • 6
    I think you mix up Mac OSX and Windows defaults here. CTR + - actually is the shortcut on OSX while CMD + - does zoom out there. Commented Feb 21, 2016 at 19:55
  • 3
    Use Visual Studio Keymap extension - marketplace.visualstudio.com/… Commented Mar 9, 2018 at 19:03
  • 3
    As of VS Code 1.28, you can go to the last edit location using Ctrl+K Ctrl+Q - code.visualstudio.com/updates/… Commented Oct 9, 2018 at 0:35

19 Answers 19

2463

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

toddmo
22.7k14 gold badges104 silver badges120 bronze badges
answered Feb 16, 2016 at 12:48
Sign up to request clarification or add additional context in comments.

28 Comments

I wonder why Microsoft decided to have different hot keys than regular visual studio. This is very annoying switching having to switch back and forth.
Can you do this with your mouse? In other IDEs the back gesture/button navigates back as well.
Kind of an annoying binding for windows, unfortunately :( Would've been good to have the same as visual studio.
@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.
searching workbench.action.navigateBack & workbench.action.navigateForward under Preferences > Keyboard Shortcuts worked for me, since I had an extension changing the default behaviour
|
152

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?

Georg Plaz
6,0075 gold badges43 silver badges66 bronze badges
answered Feb 21, 2016 at 19:53

7 Comments

Ctrl+Left and Ctrl+Right are reserved for switching between full-screens, aren't they?
@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".
Use this to make those changes code.visualstudio.com/docs/getstarted/…
Is there a way I can assign my mouse forward and backward buttons to navigate?
Great answer. Also you can find it through File → Preferences → Keyboard Shortcuts then searching Go Back and Go Forward
|
125

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 + ➡️

answered Nov 14, 2016 at 15:13

2 Comments

I'm using linux and the default keymap didn't work. I modified to Alt+Left and worked like a charm.
File/preferences/Keyboard shortcut [Ctrl-K Ctrl-S] then search "workbench.action.navigateBack". Had to set it on Linux.
34

To answer for your question, for:

  1. Windows use Alt+ for backward, and Alt+ for forward navigation.
  2. macOS use Ctrl+- for backward, and Ctrl+Shift+- for forward navigation.
  3. 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.

the Tin Man
161k44 gold badges222 silver badges308 bronze badges
answered Feb 12, 2018 at 9:16

2 Comments

You have switched windows and mac bindings.
as perrier said you have switched the window and mac
34

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.

  1. Open Settings: Code > Preferences > Keyboard Shortcuts
  2. Find Go Forward and Go Back and set them to whatever you like.
  3. 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.

gif showing the process of setting up the new keyboard shortcuts

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.

Georg Plaz
6,0075 gold badges43 silver badges66 bronze badges
answered Jun 16, 2022 at 15:20

1 Comment

I'm on Mac with VSCode 1.87.2 and I don't have Code > Preferences settings. The new option is: Code > Settings... > Keyboard Shortcuts or CMD+K+S.
26

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.

enter image description here

enter image description here

answered Oct 14, 2021 at 7:03

2 Comments

Apparently now this is built into VSCode: stackoverflow.com/a/75892641/399435
Good call @KarthicRaghupathi I didn't even notice!
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!

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
answered Dec 17, 2016 at 17:10

1 Comment

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

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 locations
  • canNavigateForwardInNavigationLocations: Whether it is possible to go forward in navigation locations
  • canNavigateToLastNavigationLocation: Whether it is possible to go to the last navigation location
  • canNavigateBackInEditLocations: Whether it is possible to go back in edit locations
  • canNavigateForwardInEditLocations: Whether it is possible to go forward in edit locations
  • canNavigateToLastEditLocation: Whether it is possible to go to the last edit location
answered Feb 21, 2022 at 19:33

Comments

11

Mac OS (MacBook Pro):

Back: Ctrl(control) + - (hyphen)

Back forward: Ctrl + Shift + - (hyphen)

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
answered Oct 13, 2018 at 12:47

Comments

9

Use Alt + /

You can find all shortcuts in Key Bindings for Visual Studio Code .

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
answered Oct 24, 2016 at 7:31

Comments

8

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.

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
answered Jul 10, 2019 at 18:42

1 Comment

These arrows are now accessible out of the box. They are to the left of the search field in the window title.
7

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.

answered Sep 23, 2022 at 15:38

Comments

6

You can go to menu FilePreferencesKeyboard 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.

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
answered Jul 31, 2020 at 13:53

1 Comment

Ctrl + Alt + - on Linux (Visual Studio Code 1.54.3 on Ubuntu MATE 20.04 (Focal Fossa)).
5

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:

  1. Go to Definition
  2. Poke around at the definition for a while (i.e., move the cursor around)
  3. 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.

answered Oct 1, 2021 at 19:07

Comments

5

if you want you can also define your own keybindings for navigation


 {
 "command": "workbench.action.navigateForward",
 "key": "cmd+alt+[ArrowRight]"
 },
 {
 "command": "workbench.action.navigateBack",
 "key": "cmd+alt+[ArrowLeft]"
 },
answered Mar 19, 2024 at 6:53

Comments

3

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.

Go back/Forward selection -- https://user-images.githubusercontent.com/900690/73729489-6ca7da80-4735-11ea-9345-1228f0302110.gif

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
answered Feb 26, 2020 at 17:22

Comments

3

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:

enter image description here

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:

  1. Go to the Last Edit Location
  2. Cursor Undo (meaning: go to last cursor location)
  3. Cursor Redo (Opposite of above)
answered Jan 18, 2022 at 17:36

1 Comment

Ctrl+Shift+P brings you directly to the Commands list (eliminates the need to type >)
1

I am on macOS (Sequoia 15.1.1), M4 Macbook Pro and I was able to achieve the cursor movements (back and forth) using Command + Option + Left / Right by default without making any changes to my system.

answered Dec 16, 2024 at 14:33

Comments

0

Best way is to use ctrl/command + P and then type "navigate back" and see the shortcut when you forget the shortcut or are trying to memorize. You can also use this for all shortcuts.

answered Sep 16 at 6:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.