Visual Studio Code (VS Code) is an open-source code editor that supports many different programming languages.
Using a full-featured editor such as VS Code provides many advantages over a plain text editor, such as:
- intelligent code completion
- convenient navigation in the code
- refactoring tools
- build automation (no need for the command-line)
- a graphical front end for GIT
- many other tools such as debugging, code formatting, showing call hierarchies etc.
The purpose of this page is to document how to set up VS Code for developing QMK Firmware.
This guide covers how to configure everything needed on Windows and Ubuntu 18.04
Before starting, you will want to make sure that you have all of the build tools set up, and QMK Firmware cloned. Head to the Newbs Getting Started Guide to get things set up, if you haven't already.
-
Git for Windows (This link will prompt to save/run the installer)
- Disable all of the options but
Git LFS (Large File Support)
andCheck daily for Git for Windows updates
. - Set the default editor to
Use Visual Studio Code as Git's default editor
- Select the
Use Git from Git Bash only
option, since that's the option that you should use here. - For the
Choosing HTTPS transport backend
, either option should be fine. - Select the
Checkout as-is, commit Unix-style line endings
option. QMK Firmware uses Unix style commits. - For the extra options, leave the default options as is.
This software is needed for Git support in VS Code. It may be possible to not include this, but it is much simpler to just use this.
- Disable all of the options but
-
Git Credential Manager for Windows (Optional)
This software provides better support for Git by providing secure storage for git credentials, MFA and personal access token generation.
This isn't strictly needed, but we would recommend it.
- Head to VS Code and download the installer
- Run the installer
This part is super simple. However, there is some configuration that we need to do to ensure things are configured correctly.
Now, we will set up the MSYS2 window to show up in VSCode as the integrated terminal. This has a number of advantages. Mostly, you can control+click on errors and jump to those files. This makes debugging much easier. It's also nice, in that you don't have to jump to another window.
-
Click File > Preferences > > Settings
-
Click on the {} button, in the top right to open the
settings.json
file. -
Set the file's content to:
{ "terminal.integrated.profiles.windows": { "QMK_MSYS": { "path": "C:/QMK_MSYS/usr/bin/bash.exe", "env": { "MSYSTEM": "MINGW64", "CHERE_INVOKING": "1" }, "args": ["--login"] } }, "terminal.integrated.cursorStyle": "line" }
If there are settings here already, then just add everything between the first and last curly brackets and separate the existing settings with a comma from the newly added ones.
?> If you installed MSYS2 to a different folder, then you'll need to change the path for terminal.integrated.shell.windows
to the correct path for your system.
-
Hit Ctrl-
`
(Grave) to bring up the terminal or go to View > Terminal (commandworkbench.action.terminal.toggleTerminal
). A new terminal will be opened if there isn‘t one already.This should start the terminal in the workspace's folder (so the
qmk_firmware
folder), and then you can compile your keyboard.
- Head to VS Code and download the installer
- Run the installer
- That's it
No, really, that's it. The paths needed are already included when installing the packages, and it is much better about detecting the current workspace files and parsing them for IntelliSense.
There are a number of extensions that you may want to install:
- Git Extension Pack - This installs a bunch of Git related tools that may make using Git with QMK Firmware easier.
- clangd - [Optional] - This is the language server for C/C++ that VS Code uses. It provides IntelliSense and other features.
- EditorConfig for VS Code - [Optional] - Helps to keep the code to the QMK Coding Conventions.
- GitHub Markdown Preview - [Optional] - Makes the markdown preview in VS Code more like GitHub's.
- VS Live Share Extension Pack - [Optional] - This extension allows somebody else to access your workspace (or you to access somebody else's workspace) and help out. This is great if you're having issues and need some help from somebody.
Restart once you've installed any extensions.
- Click File > Open Folder
- Open the QMK Firmware folder that you cloned from GitHub.
- Click File > Save Workspace As...
Using the standard compile_commands.json
database, we can get the VS code clangd extension to use the correct includes and defines used for your keyboard and keymap.
- Run
qmk generate-compilation-database -kb <keyboard> -km <keymap>
to generate thecompile_commands.json
. - Inside VS code, press Ctrl + Shift + P (macOS: Command + Shift + P) to open the command palette.
- Start typing
clangd: Download Language Server
and select it when it appears. Note that this only needs to be done once on clangd extension installation, if it didn't already ask to do so. - Inside VS code, press Ctrl + Shift + P (macOS: Command + Shift + P) to open the command palette.
- Start typing
clangd: Restart Language Server
and select it when it appears.
Now you're ready to code QMK Firmware in VS Code!