Skip to content

rcorre/qmkfmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

caf37d5 · Mar 20, 2025

History

40 Commits
Dec 26, 2024
Mar 20, 2025
Mar 20, 2025
Mar 20, 2025
Dec 23, 2024
Dec 26, 2024
Mar 20, 2025
Mar 20, 2025
Dec 26, 2024
Mar 20, 2025
Dec 26, 2024

Repository files navigation

QMK Format

qmkfmt is a tool to format the keymaps section of a keymap.c file in qmk. It formats each LAYOUT entry under keymaps into a grid with aligned columns.

Bug reports, feature requests, and contributions are welcome!

Installation

Pre-compiled binaries are available on the releases page.

To install the latest release from crates.io:

cargo install qmkfmt

To install the latest from git:

cargo install --git https://github.com/rcorre/qmkfmt

Behavior

qmkfmt is designed to work out of the box with no configuration. qmkfmt infers the number of rows from the number of lines in each LAYOUT. If a row has less than the maximum number of columns (e.g. a thumb cluster), it is centered.

For example, the following keymap:

[0] = LAYOUT_split_3x6_3(
KC_TAB,KC_Q,KC_W,KC_E,KC_R,KC_T,KC_Y,KC_U,KC_I,KC_O,KC_P,KC_PIPE,
KC_ESC,LALT_T(KC_A),RGUI_T(KC_S),LCTL_T(KC_D),LSFT_T(KC_F),KC_G,KC_H,RSFT_T(KC_J),RCTL_T(KC_K),RGUI_T(KC_L),RALT_T(KC_SCLN),KC_QUOT,
KC_LSFT,KC_Z,KC_X,KC_C,KC_V,KC_B,KC_N,KC_M,KC_COMM,KC_DOT,KC_SLSH,KC_RSFT,
KC_SPC,LT(LYR_NAV, KC_TAB),KC_ESC,LT(1, KC_ENT),KC_BSPC,KC_ESC
)

Will be reformatted to:

[0] = LAYOUT_split_3x6_3(
    KC_TAB,  KC_Q,         KC_W,         KC_E,         KC_R,                KC_T,   KC_Y,          KC_U,         KC_I,         KC_O,         KC_P,            KC_PIPE,
    KC_ESC,  LALT_T(KC_A), RGUI_T(KC_S), LCTL_T(KC_D), LSFT_T(KC_F),        KC_G,   KC_H,          RSFT_T(KC_J), RCTL_T(KC_K), RGUI_T(KC_L), RALT_T(KC_SCLN), KC_QUOT,
    KC_LSFT, KC_Z,         KC_X,         KC_C,         KC_V,                KC_B,   KC_N,          KC_M,         KC_COMM,      KC_DOT,       KC_SLSH,         KC_RSFT,
                                         KC_SPC,       LT(LYR_NAV, KC_TAB), KC_ESC, LT(1, KC_ENT), KC_BSPC,      KC_ESC
)

If clang-format is available on $PATH, qmkfmt will invoke it to format the rest of the file. You can pass --clang-format=/path/to/clang-format to use a specific clang-format, or --no-clang-format to disable this.

Configuration

The --split-spaces flag controls the given number of spaces in the center of each layout. Pass --split-spaces=0 if the keyboard is not split and you want no separation between halves.

Usage

CLI

Simply run qmkfmt path/to/keymap.c to format the file inline. If not given a path, qmkfmt reads stdin and writes to stdout.

Helix

Put the following in .helix/languages.toml at the root of the qmk_firmware repository:

[[language]]
name = "c"
auto-format = true
formatter = { command = "qmkfmt", args = ["--split-spaces=8"] }