I saw my course instructor do this, and i would like to know if there is a shortcut already existing or if there is a keybinding i can set.
What i want is, when i am currently editing a file for example, i am in ~/src/components/dashboard/dashboard.js and i press the shortcut and it takes me to the file explorer where i will be allowed to name the new file in the same directory, ie ~/src/components/dashboard/
I basically want the functionality we get when we click on the folder that we want a new file in, and then click the new File icon
CodePudding user response:
This should be as trivial as just invoking the "explorer.newFile"
command; it has a default binding that only works while the Explorer viewlet has focus; it looks like this on Windows:
{
"key": "ctrl n",
"command": "explorer.newFile",
"when": "explorerViewletFocus"
}
... so it's a matter of assigning a new shortcut that does the same, but without the when
clause:
{
"key": "<YOUR SHORTCUT>",
"command": "explorer.newFile"
}
You can still add the when
clause that would help if you want to reuse the shortcut (e.g. opening a new terminal while the terminal has focus):
{
"key": "<YOUR SHORTCUT>",
"command": "explorer.newFile",
"when": "editorTextFocus"
}
A full reference about the when
clause can be found here: https://code.visualstudio.com/api/references/when-clause-contexts