英文:
How can I add a keybinding to open the active file in the Explorer and move focus to the editor?
问题
I'd like to change the 'o' keybinding when in the file explorer of VS Code.
For a directory I'd like to keep the expand/collapse behavior, but for files I'd like the file to open (current behavior) and for the cursor to move to the editor.
英文:
I'd like to change the 'o' keybinding when in the file explorer of VS Code.
For a directory I'd like to keep the expand/collapse behavior, but for files I'd like the file to open (current behavior) and for the cursor to move to the editor.
答案1
得分: 1
你可以通过以下方式实现这个操作(在命令面板中使用 Preferences: Open Keyboard Shortcuts (JSON)
打开 keybindings.json 文件):
{
// 打开文件并将焦点传递给编辑器
"key": "o",
"when": "filesExplorerFocus && !explorerResourceIsFolder",
"command": "explorer.openAndPassFocus"
},
{
// 切换文件夹折叠
"key": "o",
"when": "filesExplorerFocus && explorerResourceIsFolder",
"command": "list.select"
}
如果你仍然想要能够在资源管理器中输入文件名以进行快速搜索,尝试将以下内容添加到 when 条件中 && !inputFocus && !textInputFocus && !inInteractiveInput && !renameInputVisible
。
英文:
You can do this with the following (open keybingings.json with Preferences: Open Keyboard Shortcuts (JSON)
in the command palette):
{
// open file and pass focus to editor
"key": "o",
"when": "filesExplorerFocus && !explorerResourceIsFolder",
"command": "explorer.openAndPassFocus"
},
{
// toggle folder folding
"key": "o",
"when": "filesExplorerFocus && explorerResourceIsFolder",
"command": "list.select"
}
If you still want to be able to type file names to do quick searches in the Explorer, try adding the following to the when-clauses && !inputFocus && !textInputFocus && !inInteractiveInput && !renameInputVisible
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论