tvrtko
tvrtko

Reputation: 500

VSCode: Prevent file from opening in a new tab and instead focus to already opened tab in another pane

I have two files open side by side like shown in the picture:

Split panes.

If I Ctrl+Click the function name two in the left pane, I want VSCode to switch focus to already opened file second.py in the right pane. Instead, VSCode opens file second.py in a new tab in the current left pane (in a place indicated by red rectangle). Now you have three tabs instead of two, and first.py is obscured from view.

How can I change this behavior so that VSCode focuses already opened tab, instead of opening a new, redundant tab?

Upvotes: 14

Views: 2003

Answers (2)

Farrah Stark
Farrah Stark

Reputation: 620

I solved this in VS Code on windows by doing the following:

  • press ctrl + p
  • type > settings json
  • open the one in your user folder
  • At the root level of the JSON add:
"window.openFilesInNewWindow": "off",
"workbench.editor.enablePreview": false

"workbench.editor.enablePreview": false" means when you click a file it stays open. This is an optional part of this solution but I think it makes for a better DX.

"window.openFilesInNewWindow": "off" means when you open a file it will focus the tab of that file if it is already open.

Upvotes: 3

Zenit_swe
Zenit_swe

Reputation: 381

Perhaps this wasn't available when the question was posted here but there's dedicated setting to do this now:

"workbench.editor.revealIfOpen": true

Upvotes: 23

Related Questions