visual-studio-code

Create new untitled file and open language mode quick pick


I have this macro

"macros": {
    "newScratchFile": [
        "workbench.action.files.newUntitledFile",
        "workbench.action.editor.changeLanguageMode"
    ]
},

Which used to work great with this extension but it appears Microsoft broke it as some point in time.

Now when I activate it, I do get a new untitled file, and the language mode popup opens for a split second but then disappears before I get a chance to type anything.

Is there a way to fix my macro so the language picker remains open?


Solution

  • Since VS Code 1.70, you can use runCommands:

    {
        "key": "ctrl+b",
        "command": "runCommands",
        "args": { "commands": [
            "workbench.action.files.newUntitledFile",
            "workbench.action.editor.changeLanguageMode"
        ]},
    },
    

    I just tested on VS Code 1.89 and it works.

    If you want keybindings that create new files in specific language modes, see VS Code keybinding to open new-untitled file with specific language mode?. Or, to change the default language mode for all new untitled files, see Change VSCode Default Language for new files?.