如何通过快捷方式打开灯泡?

有些语言支持显示灯泡的代码操作,该灯泡为警告/错误提供快速修复(更多信息参见 https://code.visualstudio.com/docs/editor/editingevolved#_code-action)。 我喜欢这个功能,但我不喜欢点击灯泡。不幸的是,我找不到一个 在当前光标位置打开灯泡的快捷方式。 我怎样才能创造这样一条捷径呢?

我尝试为 vscode.executeCodeActionProvider创建一个快捷方式,方法是像下面这样创建一个自定义密钥绑定:

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

但每次我走捷径都会收到警告

运行提供的命令: ‘ vscode.ExecuteCodeActionProvider’失败。

28801 次浏览

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 + ..

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