4
votes

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.

2

2 Answers

5
votes

(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.

2
votes

@Mark's answer almost gets you there, but it doesn't work with new (one tab) panes. Here's a modified version of his settings.json edit that does.

  1. Install the multi-command extension

  2. Put this in settings.json

    "multiCommand.commands": [
      {
        "command": "multiCommand.openFileInActiveEditor",
        "sequence": [
          "workbench.action.acceptSelectedQuickOpenItem",
          "workbench.action.previousEditor",
          "workbench.action.closeActiveEditor",
          "workbench.action.closeQuickOpen"
        ]
      }
    ]
    
  3. Put this in keybindings.json and replace the dummy value for the key key with your desired key combination

    {
      "key": "some+key+combination",
      "command": "extension.multiCommand.execute",
      "args": { "command": "multiCommand.openFileInActiveEditor" },
      "when": "inFilesPicker && inQuickOpen"
    },