Carlos Torrecillas Carlos Torrecillas - 1 year ago 117
C# Question

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

I'm trying to get a shortcut to add a new file under my current working folder. So I navigate to the explorer using

and when I get to the folder I want to create a new class I do
which creates me a new file but is not saved anywhere (I'm trying to get a similar behaviour to what ReSharper does for instance).

Is there any other shortcut to get the file created under the folder you have the focus in the explorer? Essentially I could like to get the text box to fill in the name then the file gets automatically saved so that I don't get the prompt later on.

I'm using for reference the following page:

Answer Source

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

Hit cmd+shift+p type key and hit enter on Open Keyboard Shortcuts

This will open up your default keybindings on the left and custom bindings on the right.

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": "workbench.action.files.newFile" }

When you save this you will be able to create files in folders using the procedure you outlined in your answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download