Stians Tech Tips logoStians Tech Tips

New file shortcut in vscode

vscode · productivity · shortcut

Change the default Ctrl+n shortcut in vscode to create a new file in the file explorer instead of an “Untitled” file not saved anywhere.

By default Ctrl+n (CMD+n on a Mac) creates a new blank draft named “Untitled” that is not saved (other than as a temp file managed by vscode).

If you remove this shortcut, and instead bind Ctrl+n to the action explorer.newFile, you get a new file in the current folder in the file explorer in vscode, just like if you right click on a folder and choose New File.

I find this much more helpful, as whenever I create a new file when I am working on a project, I usually want to give the file a name, and place it somewhere in the folder structure. Since you give the new file an extension, you also get get the correct syntax highlighting and autocompletion for the file type right away.

To change keyboard shortcuts in vscode either open the command palette (Ctrl+Shift+p/CMD+Shift+p) and type “Preferences: Open Keyboard Shortcuts” or use Ctrl+k,Ctrl+s to open the shortcut preferences.

New file screenshot