Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 666
tvrtko Avatar asked Dec 07 '25 04:12

tvrtko


2 Answers

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

"workbench.editor.revealIfOpen": true
like image 111
Zenit_swe Avatar answered Dec 08 '25 20:12

Zenit_swe


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.

like image 28
Paul Stegler Avatar answered Dec 08 '25 21:12

Paul Stegler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!