How I can make `ctrl + click` to go to definition in visual studio code editor for mac OS?

Solution 1:

First and foremost, please note that in VS Code for macOS, the familiar Ctrl + click from Windows / Linux operating systems has been replaced with + click (i.e.: "command + click"). Try that first before proceeding any further as that shortcut should work out of the box without any special modifications.

However, if the above still doesn't work for you then try fixing the problem by editing your settings.json file. To do that, press F1, type settings json, then click Open Settings (JSON), and then do one of the following:

To use + click as your "Go to definition" shortcut, ensure the following line exists in your JSON settings:

"editor.multiCursorModifier": "alt",

What this does is it explicitly sets VS Code's "add another cursor" shortcut to option + click (try it out for yourself!), thus freeing up + click to be used for the "Go to definition" operation.

Conversely, to use option + click as your "Go to definition" shortcut instead, add:

"editor.multiCursorModifier": "ctrlCmd",

Note: the above line will actually set the "add another cursor" shortcut to + click (not Ctrl + + click, as implied by the JSON value).

Solution 2:

Settings > User > multiCursorModifier must be set to alt (default), so the ctrl/cmd will be available to go to definition.

Documentation:

The modifier to be used to add multiple cursors with the mouse. The Go To Definition and Open Link mouse gestures will adapt such that they do not conflict with the multicursor modifier.

Solution 3:

In gear icon/keyboard shortcuts, search for f12 . Right-click on the "Go to Definition" entry and chose "Remove Keybinding". Note that will put a new entry at the end of your keybindings.json like:

{
    "key": "f12",
    "command": "-editor.action.goToDeclaration",
    "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
}

Note the "-" sign before the command, that removes that keybinding. Now copy and paste that whole entry below it (with a comma at the end of the previous entry):

{
    "key": "f12",
    "command": "-editor.action.goToDeclaration",
    "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
},
{
    "key": "cmd+enter",
    "command": "editor.action.goToDeclaration",
    "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
}

Remove the minus sign and assign whatever keybinding you like. Alternatively, go back to shortcuts file, search for "Go to Definiton" and click the pencil icon to use its interface to create a new keybinding.

Note that Ctrl-Enter is used in many contexts so you might have an unexpected conflict using such a common keybinding.