VS Code - 在选定的工作目录下添加一个新文件 [英] VS Code - Add a new file under the selected working directory

查看:30
本文介绍了VS Code - 在选定的工作目录下添加一个新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取在当前工作文件夹下添加新文件的快捷方式.所以我使用 cmd+shift+e 导航到资源管理器,当我到达文件夹时,我想创建一个新类,我执行 cmd+n 这为我创建了一个新类文件但未保存在任何地方(例如,我试图获得与 ReSharper 类似的行为).

是否有其他快捷方式可以在您在资源管理器中关注的文件夹下创建文件?基本上,我希望让文本框填写名称,然后文件会自动保存,这样我以后就不会收到提示.

我使用以下页面作为参考:https://code.visualstudio.com/文档/自定义/键绑定

解决方案

cmd+n 命令默认绑定到 workbench.action.files.newUntitledFile 但是什么你想要的是命令 explorer.newFile,默认情况下它没有绑定到快捷方式.

编辑快捷方式文件

Cmd+Shift+p 输入 key 并在 Preferences: Open Keyboard 上按 Enter快捷方式 (JSON)

这将打开 keybindings.json 文件,该文件存储当前 VS Code 用户指定的自定义键绑定.

在自定义绑定文件中输入以下内容(大概你需要输入 cmd+n 而不是 ctrl+n 但我在 windows 上所以无法测试

<预><代码>[{ "key": "ctrl+n", "command": "explorer.newFile" }]

如果您只想在浏览器聚焦时应用此功能,您可以添加一个 when 条件:

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

这样当任何其他组件被聚焦时按下 Ctrl+n 将执行默认的新文件命令

使用快捷方式界面编辑

Cmd+Shift+p 输入 key 并在 Preferences: Open Keyboard 上按 Enter快捷键

这将打开键盘快捷键首选项用户界面.

在搜索中输入explorer.newFile,找到新建文件命令,双击弹出快捷捕获模式,按下要与该命令关联的组合键.

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 to create a new class I do cmd+n 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: https://code.visualstudio.com/docs/customization/keybindings

解决方案

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.

这篇关于VS Code - 在选定的工作目录下添加一个新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆