]> git.donarmstrong.com Git - qmk_firmware.git/blob - docs/feature_leader_key.md
Keyboard: Add tkl_ansi_plus_five layout for Phantom (#4145)
[qmk_firmware.git] / docs / feature_leader_key.md
1 # The Leader Key: A New Kind of Modifier
2
3 If you've ever used Vim, you know what a Leader key is. If not, you're about to discover a wonderful concept. :) Instead of hitting Alt+Shift+W for example (holding down three keys at the same time), what if you could hit a _sequence_ of keys instead? So you'd hit our special modifier (the Leader key), followed by W and then C (just a rapid succession of keys), and something would happen.
4
5 That's what `KC_LEAD` does. Here's an example:
6
7 1. Pick a key on your keyboard you want to use as the Leader key. Assign it the keycode `KC_LEAD`. This key would be dedicated just for this -- it's a single action key, can't be used for anything else.
8 2. Include the line `#define LEADER_TIMEOUT 300` in your config.h. The 300 there is 300ms -- that's how long you have for the sequence of keys following the leader. You can tweak this value for comfort, of course.
9 3. Within your `matrix_scan_user` function, do something like this:
10
11 ```
12 LEADER_EXTERNS();
13
14 void matrix_scan_user(void) {
15   LEADER_DICTIONARY() {
16     leading = false;
17     leader_end();
18
19     SEQ_ONE_KEY(KC_F) {
20       // Anything you can do in a macro.
21       SEND_STRING("QMK is awesome.");
22     }
23     SEQ_TWO_KEYS(KC_D, KC_D) {
24       SEND_STRING(SS_LCTRL("a")SS_LCTRL("c"));
25     }
26     SEQ_THREE_KEYS(KC_D, KC_D, KC_S) {
27       SEND_STRING("https://start.duckduckgo.com"SS_TAP(X_ENTER));
28     }
29     SEQ_TWO_KEYS(KC_A, KC_S) {
30       register_code(KC_LGUI);
31       register_code(KC_S);
32       unregister_code(KC_S);
33       unregister_code(KC_LGUI);
34     }
35   }
36 }
37 ```
38
39 As you can see, you have a few function. You can use `SEQ_ONE_KEY` for single-key sequences (Leader followed by just one key), and `SEQ_TWO_KEYS`, `SEQ_THREE_KEYS` up to `SEQ_FIVE_KEYS` for longer sequences.
40
41 Each of these accepts one or more keycodes as arguments. This is an important point: You can use keycodes from **any layer on your keyboard**. That layer would need to be active for the leader macro to fire, obviously.
42
43 ## Adding Leader Key Support in the `rules.mk`
44
45 To add support for Leader Key you simply need to add a single line to your keymap's `rules.mk`:
46
47 ```
48 LEADER_ENABLE = yes
49 ```