Is it possible the prevent VS-Code from closing a file?

For context; I have a markdown file named tasks.md as a pinned tab in which I keep my todo-list. I'm accustomed to hitting Ctrl + w to close all unused files, but it also closes this pinned tab.

Is it possible to designate a file as "impossible" to close without changing a vscode setting?

Upvotes: 1

Views: 1467

Answers (2)

VonC
VonC

Reputation: 1329662

Sept. 2020, with VSCode 1.50, the PR 106385 will fix that issue.

Addresses a couple of pain points with pinned tabs:

  • Pinned tabs: add a setting to show more context #98161
  • Support pinned tabs when tabs are disabled #100211
  • Prevent closing the pinned tab when using Ctrl + W #100738

Regarding the context, this comment from Benjamin Pasero (who is part of the development team for VSCode) adds:

After a bit more thought I decided to make normal the default option for the pinnedTabSizing option because it makes sense to have the default be the normal choice and I feel that forcing a pinned tabs to shrink maybe unexpected for users that see this for the first time.

Setting it to compact or shrink should be an explicit choice by the user and is then a lot more understandable.

default sizeing

shrink


With VSCode 1.51 (Oct. 2020):

More prominent pinned tabs

Pinned tabs will now always show their pin icon, even while inactive, to make it easier to identify them.
If an editor is both pinned and contains unsaved changes, the icon reflects both states.

Inactive pinned tabs -- https://media.githubusercontent.com/media/microsoft/vscode-docs/b90c7662cebb51d859506135a03f1ff459f1c743/release-notes/images/1_51/pinned-tabs.png


And make sure to use VSCode 1.82 (Aug. 2023): issue 115734 reported "Add setting to prevent closing the pinned tab when using middle click"

A pinned tab cannot be closed with ctrl + w, but it can be closed with the mouse (middle click).

PR 188592 adds the setting:

workbench.editor.preventPinnedEditorClose:

  • always: Always prevent closing the pinned editor when using mouse middle click or keyboard.

  • onlyKeyboard: Prevent closing the pinned editor when using the keyboard.

  • onlyMouse: Prevent closing the pinned editor when using mouse middle click.

  • never: Never prevent closing a pinned editor.

Upvotes: 3

Mrinal Roy
Mrinal Roy

Reputation: 989

Without changing settings: Keyboard Binding Logic File > Preferences > Keyboard Shortcuts it's not possible currently. Upvote this Prevent closing the pinned tab when using Ctrl + W feature request in the VS Code Issue tracker. It'll get to VS Code Dev's backlog if it gets more than 20 upvotes in 60 days (August 21, 2020).

Upvotes: 1

Related Questions