Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode: Open files NOT in a new tab, reuse current tab

I believe that this is not covered by the Preview feature. I simply want to open a file for editing via Quick Open (or any way?) and replace the contents of the active tab, closing the open file and replacing it with the new one.

This behavior is central to the way I edit. Currently, I'm always opening new tabs that I don't want. It's the only barrier left between Code and the way I've used Vim for 15 years. I imagine that this is scriptable, but would like to avoid going down that road. Please tell me I'm missing something.

like image 253
WillHaslett Avatar asked Mar 03 '23 19:03

WillHaslett


1 Answers

(1) The drastic approach: search for these in your settings:

Workbench > Editor > Limit: Enabled enable this

Workbench > Editor > Limit: Value set to 1

Drastic, because it will limit you to only 1 editor tab, probably not what you want but it does reuse the active (and only tab) of course.

(2) The macro approach:

Using a macro extension like multi-command put this into your settings.json

"multiCommand.commands": [

  {
    "command": "multiCommand.openFileInActiveEditor",
    "sequence": [
      "workbench.action.closeActiveEditor",
      "workbench.action.acceptSelectedQuickOpenItem",
      "workbench.action.closeQuickOpen"   // if you want to close the quickopen panel immediately
    ]
  }
]

and in keybindings.json:

{
  "key": "alt+0",  // whatever you want
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.openFileInActiveEditor" },
  "when": "inFilesPicker && inQuickOpen"
},

It appears that you cannot override the usual right keybinding from the quickOpen panel so I set it to alt+right instead but you can pick whatever you want.

like image 102
Mark Avatar answered Mar 05 '23 19:03

Mark