VS Code - Add a new file under the selected working directory

后端 未结 4 623
猫巷女王i
猫巷女王i 2021-01-29 21:38

I\'m trying to get a shortcut to add a new file under my current working folder. So I navigate to the explorer using cmd+shift+e and when I get to the folder I want

4条回答
  •  自闭症患者
    2021-01-29 22:07

    The cmd+n command is by default bound to workbench.action.files.newUntitledFile but what you want is the command explorer.newFile which by default is not bound to a shortcut.

    Edit shortcuts file

    Hit Cmd+Shift+p type key and hit enter on Preferences: Open Keyboard Shortcuts (JSON)

    This will open keybindings.json file which stores custom keybindings specified by the current VS Code user.

    Enter the following in the custom bindings file (presumably you need to enter cmd+n instead of ctrl+n but I'm on windows so can't test

    [
      { "key": "ctrl+n", "command": "explorer.newFile" }
    ]
    

    If you want to only have this apply when the explorer is focused you can add a when condition:

    { "key": "ctrl+n", "command": "explorer.newFile", "when": "explorerViewletFocus" }
    

    This way when any other component is focused pressing Ctrl+n will execute the default new file command

    Edit using shortcuts UI

    Hit Cmd+Shift+p type key and hit enter on Preferences: Open Keyboard Shortcuts

    This will open up the keyboard shortcut preferences UI.

    Type explorer.newFile in the search to find the new file command, double click it to bring up the shortcut capture modal and press the key combination you want to associate with this command.

提交回复
热议问题