When using VSCode on Windows, I can navigate the file explorer and hit Enter on the focused file and the file will open in the editor. On my Mac, however, when I do this, VSCode will open the rename input as follows:
I'm not sure why it does this. Even in other text editors (eg Atom), the default behavior is to open the file on Enter . Is there any way to change this behavior so that the file opens on Enter ? The only workaround I've found so far is CTRL + Enter , which opens the file in a new pane, but with a 3 pane limit in VSCode, this is quite limiting.
If anyone else comes across this problem, the keyboard shortcut to open a file from the file explorer in VSCode on a Mac is:
CMD + Down
This also works in Finder.
I ended up compiling a few solutions here together to get the following keybinding.json
editions (Open via 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"
}
In version 1.19.2, on the mac I was able to go to keyboard shortcuts (menu bar > code > preferences > keyboard shortcuts), search for "rename," and edit "renameFile" ("When" value is "explorerViewletVisible && filesExplorerFocus && !inputFocus") changing the shortcut to "cmd+enter."
You can also past the following in your keybindings.json (there's a link to it on the keyboard shortcuts page):
{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !inputFocus"
}
Enter now opens the highlighted file in the explorer and ctrl+enter puts it in rename/edit mode.
–Edit–
After I upgraded to 1.21.0 the enter key started functioning as renameFile again. cmd+enter still functioned as renameFile as well. To fix this either go to menu bar > code > preferences > keyboard shortcuts and right-click the offending entry and remove it or add a hyphen/minus sign to the beginning of the command in keybindings.json:
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}
在我的 Mac 上,只需按空格键即可为我打开文件。
So I ran into this as well, but the keyboard shortcuts that I ended using is to map cmd+enter
to rename and removing the renameFile from enter
.
{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
},
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
}
cmd+down
does NOT work for me using VSCode 1.10.2 on Mac 10.10.5.
However, cmd+enter
does work for me.
Or if you want to set your own keybinding to open a file from File Explorer, add these lines to your keybindings.json
:
// open file from File Explorer
{ "key": "enter", "command": "list.select",
"when": "explorerViewletVisible && filesExplorerFocus" },
(Of course, you can change enter
to any key combination you want).
I tried to remove the shortcut of "Rename", which has the Keybinding of "Enter". Then it opens the file properly when I press "Enter".
For me, I have to do command
0
and then do a command
down
This brings me to the explorer and then opens the file I select. In Atom, I just had to hit enter
to open the file, I find this to be a strange behavior. vscode v 1.21.1
on OSX
In preferences:
Code -> Preferences -> Keyboard Shortcuts
Add this to your keybindings.json
{
"key": "ctrl+n",
"command": "workbench.action.files.newFile"
}
within the array that may or may not contain other keybindings you have set. Save keybindings.json
Then when you navigate to a directory in the file explorer, you can create a new file with ctrl+n
Not sure why the "enter" behavior is different, I am not sure "enter" alone is set in the keybindings on your system or its just defaults to different behaviors based on OS standards...
The good news is, what you are looking for is CTRL+P or CTRL+O
CTRL+P let's you find a file, and CTRL+O should open it (the exact behavior you'd like)
You may also be able to add "Enter" as a possibility for the "workbench.action.files.openFile" command, but not sure if that will break anything if you do. Try it, or just get used to using CTRL+O on both platforms!
More info:
https://code.visualstudio.com/Docs/customization/keybindings
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.