159

I'm currently using VSCode and am trying to use the F12 shortcut which takes me to a definition of an object/function. When I want to go back to the reference, I can't seem to find the right way to do it. With VS community I used Shift + F12.

I've try different combinations, such as Alt + F12 or Shift + F12 but all I get is a peek definition of the element which is not useful at all; it's just a popup showing the same element in the same file I'm at. I've seen answers to this question but pertaining to VS 2010 which are no longer applicable or doesn't work with VSCode.

Question: What is the shortcut to Go Back once you've used F12 to Go to the definition?

Penny Liu
17.9k5 gold badges89 silver badges109 bronze badges
asked Feb 27, 2017 at 18:14
1

17 Answers 17

208

For macOS it is ⌃- (Ctrl + -) by default. And for Windows: (Alt + LeftArrow)

answered Aug 21, 2017 at 23:26
Sign up to request clarification or add additional context in comments.

3 Comments

(Alt + LeftArrow) does not work on Windows
If it doesn't go to vscode setting then shortcuts. Search for Go Back command and bind it with Alt + LeftArrow. For it was default setting.
this works on macOS
48

According to the vscode keyboard shortcuts documentation page, the navigateBack action defaults to Ctrl+Alt+-.

In my keybindings.json file, I've rebound it to ctrl+- using:

{ "key": "ctrl+-", "command": "workbench.action.navigateBack" }

Andy Li
6,0536 gold badges39 silver badges52 bronze badges
answered Feb 27, 2017 at 20:42

1 Comment

I'm not sure but I think that takes you back/forward to where your cursor/highlight text was last, as opposed to toggling between object and definition.
26

You can open the Keyboard Shortcuts to find the shortcuts.

Preferences> Keyboard Shortcuts

Search for Go, and it’ll show the Go Back and Go Forward shortcuts.

In macOS:

Go Back: ⌃- (Ctrl+-)

Go Forward: ⌃⇧- (Ctrl+shift+-)

[
 {
 "command": "workbench.action.navigateBack",
 "key": "ctrl+-"
 },
 {
 "command": "workbench.action.navigateForward",
 "key": "ctrl+shift+-"
 }
]
Florian Wendelborn
1,7671 gold badge21 silver badges30 bronze badges
answered Dec 13, 2017 at 5:02

Comments

19

Shift + F12 should be working for you. There is a box on the right of the peek view which lists all the references. You are seeing the peek view to the reference you went to (the definition) but on the right are more. That boundary between the two can be dragged left and right so perhaps yours is not visible - trying dragging the peek view box right boundary to the left after you hit Shift+F12. Do you see a list of references there? Double-clicking the one you started from originally will take you back to it.

Edit:

v1.29 added some nice functionality for listing the references in the sidebar. See references view.

List All References in the context menu or Shift+Alt+F12

Results are stable and individual results can be cleared, which is great if you use the view as a To Do list. You can use F4 and Shift+F4 to navigate through results without taking your hands off the keyboard.

Nik
3,2552 gold badges27 silver badges25 bronze badges
answered Feb 27, 2017 at 20:09

1 Comment

Thanks Mark, you're right. Although it now seems to be working. For some reason I wasn't getting that extra content you mention in that box. It would've been nice for Shift + F12 to have taken you straight to the file it refers to instead of that popup (as VS community does) but, I guess, it's perhaps a matter of taste. Maybe I'm yet to discover how to do it.
19

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

ref

answered Nov 27, 2021 at 19:43

Comments

17

ALT + Left Arrow and ALT + Right Arrow worked for me. VS code listed all shortcuts in pdf keyboard-shortcuts-windows.pdf. To see all keyboard shortcuts go to menu bar Help->Keyboard Shortcuts Reference. It will open pdf that contains all shortcuts.enter image description here

answered Feb 18, 2020 at 6:29

2 Comments

alt + F12 on linux
These shortcuts will be changing with respect to versions and OS. In my Ubuntu System, with Version 1.60.2, 'Ctrl+Alt+-' did the job. So Better open the help page and verify.
13

For those using the VSCodeVim extension, it would be Ctrl + o and Ctrl + i

answered Feb 7, 2020 at 18:19

Comments

11

Alt + Left arrow worked for me or Go menu and then Back.

Nik
3,2552 gold badges27 silver badges25 bronze badges
answered Jul 17, 2018 at 11:47

Comments

9

Try goto-symbol-stack.

This extension implements a stack tracking the positions only when the goto-definition is triggered by Alt+], and allows the user go back to the reference using Alt+[. No annoying cursor movement in the stock navigation(Alt+).

answered Oct 12, 2018 at 17:52

1 Comment

This is the only correct answer! Alt + is not the inverse of F12! I often go to the definition of a symbol, have a look round, and then want to return to the start of my excursion without visiting all the intermediate stops.
7

An alternative approach is to use the Ctrl+Alt+Click shortcut, which will open the definition in a new pane to the right. This can then be closed with the usual Ctrl+F4 key combination.

Paul Roub
36.5k27 gold badges88 silver badges95 bronze badges
answered Dec 19, 2017 at 19:01

Comments

3

1.Go Definition - F12 or Right click and Click Go to Definition Option

2.Back to Reference - Alt + Left Arrow

answered Jun 18, 2021 at 2:56

Comments

3

Go to definition F12

Back to declaration Ctrl + F12

bobbogo
15.6k3 gold badges55 silver badges60 bronze badges
answered Aug 9, 2018 at 7:46

2 Comments

Only works properly if you only have a single use of the variable in sight!
this rocks. Thanks. Only this worked for me in 2024 Jan
2

Next : Ctrl + F12

Back : Alt + LeftRow (<--)

For Windows is working.

answered Nov 18, 2021 at 12:25

Comments

0

I have a similar problem. Fix it by installing this JDK 8 to VSCode

answered Mar 30, 2021 at 11:40

Comments

0

In Version: 1.62.3 under Ubuntu:
it's just F12 again

it's bound to both:

  • Go to Definition
    and
  • goToNextReference
answered Dec 2, 2022 at 2:00

Comments

0

For C++, with clangd extension, without intellisense I have:

  • kept F12 mapped to Go to Definition
  • remapped Ctrl + F12 to Go to Declaration (removed pre-existing mappings on Ctrl + F12 which where not useful).

Note: with clangd extension Alt + O is mapped to clangd: Switch Between Source/Header which can also be useful.

answered Mar 15, 2024 at 13:58

Comments

0

First, make sure you have Python plugins installed.

answered Feb 1 at 3:56

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.