142

If I accidentally press any key and the cursor goes somewhere else, how do I return to previous location? What is shortcut key for that?

Any extension that may help.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Ganesh
  • 3,128
  • 2
  • 17
  • 27

1 Answers1

299

This function is called "navigate Back", you find it also in the Key Bindings for Visual Studio Code and more accessible within vscode from the keybindings UI.

OS default keybinding for navigateBack
Mac Ctrl + -
Windows Alt + Left
Linux Ctrl + Alt + -
OS default keybinding for navigateForward
Mac Ctrl + Shift + -
Windows Alt + Right
Linux Ctrl + Shift + -
Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38
Dmitry Gorshkov
  • 3,523
  • 4
  • 18
  • 20
  • 15
    Great! Also, adding `SHIFT` will reverse the action and take you to the next location, so you can easily go back and forth. – Aurelio Dec 07 '18 at 10:59
  • 5
    @Nobita: to go to the next location, you can also use Alt + Right arrow. – tala9999 Mar 20 '19 at 19:42
  • Also be careful that you aren't using any extensions like sublime shortcuts for vscode as that will interfere with the default key bindings of vs code. – Boolean Autocrat Mar 09 '21 at 20:59
  • alt + arrow left/right has worked for me to go back and forth also multiple times. The shortcuts in this answer not. – The Fool Oct 23 '21 at 13:18
  • I wonder just like Windows why these are not `Alt`+`Left`/`Right` for other systems. In Linux, these key combinations don't even seem to be used by any other functionalities and they could have made use of these to make the navigation easier. – hafiz031 Jul 18 '23 at 14:05