5

I have a project open, with many folders and subfolders. I would like to create a file. I know specifically which folder the file should exist in.

Is there a way to create a new file in a specific folder, without using the mouse?

Note: I've also opened an issue on the vscode github repo here, referencing suggestions from this stackoverflow: https://github.com/microsoft/vscode/issues/117509

Duane J
  • 1,615
  • 1
  • 15
  • 22
  • Create a new file using the shortcut and then save it in the desired location. If you're asking about directly creating the file in the destination as we do using the package explorer, I doubt it's available by default. There may be some plugin for that purpose – Debargha Roy Feb 23 '21 at 05:38
  • You could focus the files explorer, type your file name with the filter on (possibly arrow up/down to your chosen folder if need be) and then trigger a `newFile` command. If you want to see those steps let me know. An extension could do this. – Mark Feb 23 '21 at 06:15
  • the file explorer has 2 context menus using the mouse, one for the whole view and a specific one if a directory is selected by using `Ctrl+0` navigate with arrows and press `Enter` or select with mouse, with keyboard context key you only get the View context menu (this does not contain new file entry). File an issue to get the special context menu when directory is selected in the File Explorer – rioV8 Feb 23 '21 at 10:14

3 Answers3

7

Just in case someone ends up here, add this to your keybinding:

{
    "key": "ctrl+n",
    "command": "workbench.files.action.createFileFromExplorer",
    "when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
}

Found it in the github issue mentioned by @Duane J above

To know how to find and edit the keybindings.json file refer to this link

Leo
  • 10,407
  • 3
  • 45
  • 62
princelySid
  • 6,687
  • 2
  • 16
  • 17
1

It is also nice to create files and folders from the command line. To open the terminal, which is integrated in VSCode, press Ctrl+`.

Then to create a new file inside a folder of your choice you can use common command-line syntax such as:

touch ./<myFolder>/<newFile>


[Edit:] By the way, it is also possible to open the file just created without using the mouse. Press arrowUp and change the word "touch" to "code", which is the command to open VSCode:

code ./<myFolder>/<newFile>

  • 1
    Actually, you don't really even have to do the first one. You can just `code path/to/file` and immediately save. ;) – Eric Haynes Oct 18 '22 at 00:03
1

ctrl+k ctrl+s for open shortcut config, search for explorer.newfile and add your preferred command, can be alt+n often is unused by default. ctrl+n is by default for new untitled text file.

ccnmagnoo
  • 31
  • 2