Theme:
Tidbit
  • ide|
  • productivity

Quickfix in VS Code

Guy Waldman's ProfileGuy Waldman
July 18, 2024
Time to read:
2 minutes
What's your workflow for whenever those red squigglies appear in Visual Studio Code?
Do you jump over to that line, click the lightbulb (or even better, Ctrl+. or +.) and apply the suggested fix?
Well, no more!
You can create a shortcut or even a vim keybinding to apply the first quickfix suggestion.

##Shortcut

Open your keybindings configurations (open the command palette (Ctrl+Shift+P) and search for Preferences: Open Keyboard Shortcuts (JSON)), and add the following entry:
1{ 2 "key": "cmd+k cmd+x", // Or any other keybinding you prefer. 3 "command": "editor.action.codeAction", 4 "args": { 5 "kind": "quickfix", 6 "apply": "first" 7 } 8} 9

##Vim keybinding

Open your user settings (open the command palette (Ctrl+Shift+P) and search for Preferences: Open User Settings (JSON)) and add the following entry:
1{ 2 "before": [ 3 "<leader>", 4 "x", 5 "x" 6 ], // Or any other keybinding you prefer. 7 "commands": [ 8 { 9 "command": "editor.action.codeAction", 10 "args": { 11 "kind": "quickfix", 12 "apply": "first" 13 } 14 } 15 ] 16} 17
Note
The workspace settings file could also work, of course.
Doesn't have to be the user settings file.

##Extra: Jumping to the next error

To jump to the next error, you could add the following keybinding (to keybindings.json):
1{ 2 "key": "cmd+k cmd+n", // Or any other keybinding you prefer. 3 "commands": [ 4 "editor.action.marker.nextInFiles" 5 ] 6} 7
Or for vim (settings.json):
1{ 2 "before": ["<leader>", "n"], // Or any other keybinding you prefer. 3 "commands": ["editor.action.marker.nextInFiles"] 4} 5

##References

Related content

    • productivity|
    • ai
    Introducing: magic-cli
    Post
    July 16, 2024
    A command line utility that will make you a magician in the terminal
    • technical|
    • productivity
    Git hooks for fun & profit
    Post
    August 9, 2022
    Using git hooks for developer workflow automation
    • opinion|
    • productivity|
    • ai
    The future of software development
    Post
    June 29, 2021
    What will the future of software tooling look like?
    • technical|
    • productivity
    Loading .env files with no dependencies
    Tidbit
    July 26, 2024
    Loading .env files easily in *NIX shells with no dependencies
    • devops|
    • productivity
    GitHub Actions step outputs
    Tidbit
    July 12, 2024
    How to output data from a GitHub Actions step to reuse in a different step