如何添加一个键绑定以打开活动文件并将焦点移至编辑器?

huangapple go评论58阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月6日 22:38:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定