Visual Studio Code closes my file when I search for new ones
Asked Answered
E

4

116

I'm using Visual Studio Code for working and I use ctrl-P command to search for files in my directory.

The problem appears when I want to search for another file, it opens it in the place of the first searched file, closing it.

Is any setting for avoiding this pain?

Exciter answered 25/4, 2017 at 8:25 Comment(7)
Double-click the file header so it changes from italic to regular. Then it will stay open.Thespian
By the way that's the default way ! Try this link code.visualstudio.com/docs/editor/codebasicsSheathing
@john What's the keyboard shortcut? If you're already ctrl-p-ing your way to opening, it'd be great if you didn't have to take your hand off of the keyboard to go to [whatever comes after preview mode].Babby
@Babby Ctrl+K, Enter. If you want to reassign it, it's called workbench.action.keepEditorThespian
Whoever in the dev team decided this would be a good idea needs to be fired ASAPGilliland
You can also open the file by a double-click and it will be kept open. If it's already in preview (tab title is in italics), you can also keep it open by double-clicking the title, or Ctrl+K, Enter.Wishbone
What a stupid behaviour lol. I did this uncountable times too. :(Streptothricin
C
173

By default, VSCode opens files in preview mode. This is indicated by their name being italic in the menu bar. As John noted, you can double click on the file to fully open it.

To disable this behavior, try setting:

"workbench.editor.enablePreview": false
Cellulosic answered 25/4, 2017 at 15:38 Comment(3)
Thanks for this fix!. Amazed this isn't the default as this is the way every other editor on the planet works. Found this so frustrating.Crosstree
You can use ctrl+K, 'Enter' to keep it open. Don't forget to let go of CTRL while pressing 'Enter'.December
You can also open the file by a double-click and it will be kept open. If it's already in preview (tab title is in italics), you can also keep it open by double-clicking the title, or Ctrl+K, Enter.Wishbone
V
32

When you select a file from search result -> you will see the file open with file name italicized. This means that the file is open in preview mode. Now any other file you choose to select will replace its content in this tab.

To make this tab stick among the open tabs you can:

double click to select the file or double click on already selected file in search pane -> you will see the name of file is not italicized anymore(meaning the file is now pinned as a tab)

Alternatively,

You can use the below setting to have all selected files open as a separate tab:

"workbench.editor.enablePreview": false

This setting is found here : Files -> Preferences-> Settings

But the downside of using this is that all files you click on will remain opened and you would then need to clean tabs after your search.

Voiceless answered 13/2, 2018 at 0:19 Comment(2)
Thank you! double click is the best ideaOidea
Or on mac: Code -> settingsCestoid
J
3

Ctrl+P -- For targetting a file Alt+Enter -- For Opening that file into next tab

Juvenile answered 22/7, 2020 at 15:8 Comment(1)
On MacOS that's Cmd+P then Option+EnterHydrophane
S
2

Double click on the files instead of a single click. That worked for me.

Scripture answered 29/12, 2022 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.