How to open the lightbulb via shortcut?

Visual Studio-CodeKeyboard ShortcutsVscode Settings

Visual Studio-Code Problem Overview


Some languages support code actions which display a lightbulb providing quick fixes for a warning/error (See https://code.visualstudio.com/docs/editor/editingevolved#_code-action for more information). I like this feature but I don't like to click on the lightbulb. Unfortunately I can't find a shortcut for opening the lightbulb at the current cursor position. How can I create such a shortcut?

I tried to create a shortcut for vscode.executeCodeActionProvider by creating a custom keybinding like this:

[{ "key": "alt+enter", "command": "vscode.executeCodeActionProvider"}]

But everytime I hit the shortcut I receive the warning

> Running the contributed command:'vscode.executeCodeActionProvider' failed.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

The correct command editor.action.quickFix. The default binding on Windows looks like this:

{ "key": "ctrl+.", "command": "editor.action.quickFix",
                   "when": "editorTextFocus" }

On Mac it's CMD + ..

Solution 2 - Visual Studio-Code

If you're a JetBrains junkie and can't imagine not hammering on Alt+Enter all day long, then you can re-map the default (Ctrl+.) easily enough.

Open the File menu and select Preferences then Keyboard Shortcuts.

Type editor.action.quickFix into the search box:

enter image description here

Click the pen icon, or right-click and select Change Keybinding.

Enter your preferred shortcut into the dialog that appears, then press Enter.

enter image description here

You should end up with something that looks like:

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWosiView Question on Stackoverflow
Solution 1 - Visual Studio-CodeWosiView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeDrew NoakesView Answer on Stackoverflow