簡體   English   中英

VSCode:在 Mac OSX 上使用 Enter 鍵從文件資源管理器打開文件

[英]VSCode: Open file from file explorer with Enter key on Mac OSX

在 Windows 上使用 VSCode 時,我可以導航文件資源管理器並在焦點文件上按Enter ,該文件將在編輯器中打開。 然而,在我的 Mac 上,當我這樣做時,VSCode 將打開重命名輸入,如下所示:

在此處輸入圖片說明

我不確定它為什么這樣做。 即使在其他文本編輯器(例如 Atom)中,默認行為也是按Enter打開文件。 有沒有辦法改變這種行為,以便文件在Enter 上打開? 到目前為止,我發現的唯一解決方法是CTRL + Enter ,它會在新窗格中打開文件,但在 VSCode 中限制為 3 個窗格,這是非常有限的。

如果其他人遇到此問題,在 Mac 上的 VSCode 中從文件資源管理器打開文件的鍵盤快捷鍵是:

CMD +向下

這也適用於 Finder。

我最終在這里編譯了一些解決方案以獲得以下keybinding.json版本(通過Code > Preferences > Keyboard Shortcuts > keybindings.json打開Code > Preferences > Keyboard Shortcuts > keybindings.json ):

  {
    "key": "cmd+enter",
    "command": "renameFile",
    "when": "explorerViewletVisible && filesExplorerFocus"
  },
  {
    "key": "enter",
    "command": "-renameFile",
    "when": "explorerViewletVisible && filesExplorerFocus"
  },
  {
    "key": "enter",
    "command": "list.select",
    "when": "listFocus && !inputFocus"
  }

在 1.19.2 版本中,在 Mac 上,我可以轉到鍵盤快捷鍵(菜單欄 > 代碼 > 首選項 > 鍵盤快捷鍵),搜索“重命名”,然后編輯“重命名文件”(“何時”值為“explorerViewletVisible && filesExplorerFocus” && !inputFocus") 將快捷方式更改為“cmd+enter”。

您還可以在 keybindings.json 中粘貼以下內容(在鍵盤快捷鍵頁面上有一個鏈接):

{
  "key": "cmd+enter",
  "command": "renameFile",
  "when": "explorerViewletVisible && filesExplorerFocus && !inputFocus"
}

Enter 現在在資源管理器中打開突出顯示的文件,ctrl+enter 將其置於重命名/編輯模式。


-編輯-

升級到 1.21.0 后,回車鍵再次開始用作 renameFile。 cmd+enter 仍然起到 renameFile 的作用。 要解決此問題,請轉到菜單欄 > 代碼 > 首選項 > 鍵盤快捷鍵,然后右鍵單擊違規條目並將其刪除,或者在 keybindings.json 中的命令開頭添加連字符/減號:

{
  "key": "enter",
  "command": "-renameFile",
  "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}

在我的 Mac 上,只需按空格鍵即可為我打開文件。

所以我也遇到了這個問題,但我結束使用的鍵盤快捷鍵是映射cmd+enter以重命名並從enter刪除 renameFile 。

{
  "key": "cmd+enter",
  "command": "renameFile",
  "when": "explorerViewletVisible && filesExplorerFocus"
},
{
  "key": "enter",
  "command": "-renameFile",
  "when": "explorerViewletVisible && filesExplorerFocus"
}

cmd+down在 Mac 10.10.5 上使用 VSCode 1.10.2 對我不起作用。

但是, cmd+enter對我有用。

或者,如果您想設置自己的鍵綁定以從文件資源管理器打開文件,請將這些行添加到您的keybindings.json

// open file from File Explorer
{ "key": "enter", "command": "list.select",
                     "when": "explorerViewletVisible && filesExplorerFocus" },

(當然,您可以將enter更改為您想要的任何組合鍵)。

我試圖刪除具有“Enter”鍵綁定的“重命名”快捷方式。 然后當我按“Enter”時它會正確打開文件。

對我來說,我必須先執行command 0 ,然后再執行down command down這會將我帶到資源管理器,然后打開我選擇的文件。 在 Atom 中,我只需按enter鍵即可打開文件,我發現這是一種奇怪的行為。 OSX上的vscode v 1.21.1

  • SPACE :打開但關注資源管理器( filesExplorer.openFilePreserveFocus命令)
  • CMD+Down :打開並聚焦打開的文件( explorer.openAndPassFocus命令)

您可以在“代碼 - 首選項 - 鍵盤快捷鍵”中更改它們: 鍵盤快捷鍵(代碼 - 首選項 - 鍵盤快捷鍵)

在偏好中:

代碼 -> 首選項 -> 鍵盤快捷鍵

將此添加到您的 keybindings.json

{

    "key": "ctrl+n",
    "command": "workbench.action.files.newFile"
}

在可能包含或不包含您設置的其他鍵綁定的數組中。 保存 keybindings.json

然后當您導航到文件資源管理器中的目錄時,您可以使用 ctrl+n 創建一個新文件

不知道為什么“輸入”行為不同,我不確定“輸入”是在系統的鍵綁定中單獨設置的,還是根據操作系統標准默認為不同的行為......

好消息是,您正在尋找的是 CTRL+P 或 CTRL+O

CTRL+P 讓你找到一個文件,CTRL+O 應該打開它(你想要的確切行為)

您也可以為“workbench.action.files.openFile”命令添加“Enter”作為一種可能性,但不確定這樣做是否會破壞任何內容。 試試吧,或者只是習慣在兩個平台上使用 CTRL+O!

更多信息:

https://code.visualstudio.com/Docs/customization/keybindings

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM