How to open 'Go to definition' in other split tab for same file in VS Code?

Viewed 11581

I'm considerably new to Visual Studio Code and I am struggling a bit with an easy functionality. Imagine the case when I am reviewing some code in a file a.py and I select 'Go to definition' on a function x of the same file. Is there any possible configuration or shortcut that opens the definition on a split on the editor?

I have tried having already the same file split in the editor an it still opens the definition in the same file what is uncomfortable when you have to trace some code because you need to scroll up and down whenever you want to see another function of the same file.

An extension that allows to do the trick will also be well received. Thanks.

5 Answers

There are 2 ways to achieve this.

Either:

  1. Left-click function name that you want to open.
  2. Ctrl + t
  3. Ctrl + enter

Or:

  1. Change setting Editor > Goto Location: Multiple to be gotoAndPeek or goto
  2. Ctrl + Alt + [click on function name]

Both methods will open the definition in the split to the right (or create a new split if this is the right-most split).

You like?

[option + command + left click] or [option + command + F12] opens definition in split tab.

For me setting workbench.editor.revealIfOpen to true like described here worked.

Controls whether an editor is revealed in any of the visible groups if opened. If disabled, an editor will prefer to open in the currently active editor group. If enabled, an already opened editor will be revealed instead of opened again in the currently active editor group. Note that there are some cases where this setting is ignored, e.g. when forcing an editor to open in a specific group or to the side of the currently active group.

You have two different ways to do that task: First one is, with the cursor on the word that you want to go to definition, press Alt+F12. It opens a new tab like this one:

enter image description here

Second one is edit the settings and add this line:

"workbench.editor.enablePreview": false

It disables all the previews for code files so always that you want to go to definition, they will be open in a new tab, as you can see here:

enter image description here

Related