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

17,605

Solution 1

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

Solution 2

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.

Solution 3

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

Share:
17,605
Samurai Jack
Author by

Samurai Jack

everybody knows me

Updated on July 19, 2022

Comments

  • Samurai Jack
    Samurai Jack almost 2 years

    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?

  • desperateCoder
    desperateCoder about 4 years
    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.
  • Dmitry Grinko
    Dmitry Grinko about 4 years
    Thank you! double click is the best idea
  • Tejas
    Tejas about 4 years
    You can use ctrl+K, 'Enter' to keep it open. Don't forget to let go of CTRL while pressing 'Enter'.
  • OndroMih
    OndroMih almost 4 years
    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.
  • Purplejacket
    Purplejacket over 3 years
    On MacOS that's Cmd+P then Option+Enter