819
votes

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

10
If it's the usual VS keymap I'm used to it's Ctrl - - Sami Kuhmonen
In Visual Studio Code that shortcut corresponds to "Zoom Out: - kimsagro
I think you mix up Mac OSX and Windows defaults here. CTR + - actually is the shortcut on OSX while CMD + - does zoom out there. - OderWat
Use Visual Studio Keymap extension - marketplace.visualstudio.com/… - George Paoli
Waiting with baited breath for customization of the mouse context menu for this functionality. - gdbj

10 Answers

1425
votes

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

96
votes

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?

35
votes

This will be different for each OS, based on the information in Key Bindings for Visual Studio Code.

Go Back: workbench.action.navigateBack
Go Forward: workbench.action.navigateForward

Linux

Go Back: Ctrl+Alt+-
Go Forward: Ctrl+Shift+-

Mac OS X

⌃- / ⌃⇧-

Windows

Alt+ /

11
votes

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!

6
votes

Mac OS (MacBook Pro):

Back: Ctrl(control) + - (hyphen)

Back forward: Ctrl + Shift + - (hyphen)

5
votes

Use Alt + /

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

5
votes

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.

4
votes

The answer for your question:

  1. Mac:
    (Alt+) For backward and (Alt+) For forward navigation
  2. Windows:
    (Ctrl+-) For backward and (Ctrl+Shift+-) For forward navigation
  3. Linux:
    (Ctrl+Alt+-) For backward and (Ctrl+Shift+-) For forward navigation


You can find out the current key-bindings following this link

You can even edit the key-binding as per your preference.

2
votes

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.

0
votes

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