5 #include "quantum_keycodes.h"
7 #define NOR_MOD TO(NORMAL_MODE)
8 #define INS_MOD TO(INSERT_MODE)
10 #define PRESS(keycode) register_code16(keycode)
11 #define RELEASE(keycode) unregister_code16(keycode)
13 uint16_t VIM_QUEUE = KC_NO;
15 enum custom_keycodes {
16 PLACEHOLDER = SAFE_RANGE, // can always be here
43 void VIM_APPEND(void);
44 void VIM_APPEND_LINE(void);
46 void VIM_CHANGE_BACK(void);
47 void VIM_CHANGE_DOWN(void);
48 void VIM_CHANGE_END(void);
49 void VIM_CHANGE_INNER_WORD(void);
50 void VIM_CHANGE_LEFT(void);
51 void VIM_CHANGE_LINE(void);
52 void VIM_CHANGE_RIGHT(void);
53 void VIM_CHANGE_UP(void);
54 void VIM_CHANGE_WHOLE_LINE(void);
55 void VIM_CHANGE_WORD(void);
57 void VIM_DELETE_BACK(void);
58 void VIM_DELETE_DOWN(void);
59 void VIM_DELETE_END(void);
60 void VIM_DELETE_INNER_WORD(void);
61 void VIM_DELETE_LEFT(void);
62 void VIM_DELETE_LINE(void);
63 void VIM_DELETE_RIGHT(void);
64 void VIM_DELETE_UP(void);
65 void VIM_DELETE_WHOLE_LINE(void);
66 void VIM_DELETE_WORD(void);
70 void VIM_OPEN_ABOVE(void);
72 void VIM_SUBSTITUTE(void);
74 void VIM_VISUAL_BACK(void);
75 void VIM_VISUAL_DOWN(void);
76 void VIM_VISUAL_END(void);
77 void VIM_VISUAL_INNER_WORD(void);
78 void VIM_VISUAL_LEFT(void);
79 void VIM_VISUAL_RIGHT(void);
80 void VIM_VISUAL_UP(void);
81 void VIM_VISUAL_WORD(void);
85 void TAP(uint16_t keycode) {
90 void CMD(uint16_t keycode) {
96 void CTRL(uint16_t keycode) {
102 void SHIFT(uint16_t keycode) {
108 void ALT(uint16_t keycode) {
115 * Sets the `VIM_QUEUE` variable to the incoming keycode.
116 * Pass `KC_NO` to cancel the operation.
119 void VIM_LEADER(uint16_t keycode) {
122 case VIM_C: print("\e[32mc\e[0m"); break;
123 case VIM_CI: print("\e[32mi\e[0m"); break;
124 case VIM_D: print("\e[32md\e[0m"); break;
125 case VIM_DI: print("\e[32mi\e[0m"); break;
126 case VIM_V: print("\e[32mv\e[0m"); break;
127 case VIM_VI: print("\e[32mi\e[0m"); break;
128 case KC_NO: print("❎"); break;
133 * ####### # # ####### ##### # # ####### #######
134 * # # ## # # # # # # # # #
135 * # # # # # # # # # # # #
136 * # # # # # ##### ##### ####### # # #
137 * # # # # # # # # # # # #
138 * # # # ## # # # # # # # #
139 * ####### # # ####### ##### # # ####### #
144 * Vim-like `append` command.
145 * Works by sending →.
147 void VIM_APPEND(void) {
148 print("\e[31ma\e[0m");
150 layer_on(INSERT_MODE);
154 * Vim-like `back` command
155 * Simulates vim's `b` command by sending ⌥←
157 void VIM_BACK(void) {
158 print("\e[31mb\e[0m");
163 * Vim-like `cut` command
164 * Simulates vim's `x` command by sending ⇧→ then ⌘X.
167 print("\e[31mx\e[0m");
173 * Vim-like `down` command
176 void VIM_DOWN(void) {
177 print("\e[31mj\e[0m");
182 * Vim-like `end` command
183 * Simulates vim's `e` command by sending ⌥→
186 print("\e[31me\e[0m");
191 * Vim-like `left` command
194 void VIM_LEFT(void) {
195 print("\e[31mh\e[0m");
201 * Vim-like `open` command.
202 * Works by sending ⌘→ to move to the end of the line, `enter` to open a new line,
203 * then switching to insert mode.
205 void VIM_OPEN(void) {
206 print("\e[31mo\e[0m");
210 layer_on(INSERT_MODE);
214 * Vim-like `put` command
215 * Simulates vim's `p` command by sending ⌘V
218 print("\e[31mp\e[0m");
224 * Vim-like `put before` command
225 * Simulates vim's `P` command by sending ↑, ⌘←, then ⌘V
227 void VIM_PUT_BEFORE(void) {
228 print("\e[31mP\e[0m");
236 * Vim-like `right` command
239 void VIM_RIGHT(void) {
240 print("\e[31ml\e[0m");
246 * Vim-like `substitute` command
247 * Simulates vim's `s` command by sending ⇧→ to select the next character, then
248 * ⌘X to cut it, then entering insert mode.
250 void VIM_SUBSTITUTE(void) {
251 print("\e[31ms\e[0m");
255 layer_on(INSERT_MODE);
259 * Vim-like `undo` command
260 * Simulates vim's `u` command by sending ⌘Z
262 void VIM_UNDO(void) {
263 print("\e[31mu\e[0m");
269 * Vim-like `up` command
273 print("\e[31mk\e[0m");
279 * Vim-like `word` command
280 * Simulates vim's `w` command by moving the cursor first to the
281 * end of the current word, then to the end of the next word,
282 * then to the beginning of that word.
284 void VIM_WORD(void) {
285 print("\e[31mw\e[0m");
295 * Vim-like `yank` command
296 * Simulates vim's `y` command by sending ⌘C
298 void VIM_YANK(void) {
299 print("\e[31my\e[0m");
305 * Vim-like `yank line` command
306 * Simulates vim's `y` command by sending ⌘← then ⇧⌘→ then ⌘C
308 void VIM_YANK_LINE(void) {
309 print("\e[31mY\e[0m");
319 * ##### # # ### ####### ####### ####### ######
320 * # # # # # # # # # #
322 * ##### ####### # ##### # ##### # #
324 * # # # # # # # # # #
325 * ##### # # ### # # ####### ######
330 * Vim-like `append to line` command
331 * Simulates vim's `A` command by sending ⌘→ then switching to insert mode.
333 void VIM_APPEND_LINE(void) {
334 print("\e[31mA\e[0m");
337 layer_on(INSERT_MODE);
341 * Vim-like `change line` command
342 * Simulates vim's `C` command by sending ⌃K then switching to insert mode.
344 void VIM_CHANGE_LINE(void) {
345 print("\e[31mC\e[0m");
348 layer_on(INSERT_MODE);
352 * Vim-like 'delete line' command
353 * Simulates vim's `D` command by sending ⌃K to kill the line
355 void VIM_DELETE_LINE(void) {
356 print("\e[31mD\e[0m");
362 * Vim-like 'join lines' command
363 * Simulates vim's `J` command by sending ⌘→ to go to the end of the line, then
364 * DELETE to join the lines
366 void VIM_JOIN(void) {
367 print("\e[31mJ\e[0m");
375 * Vim-like 'open above' command
376 * Simulates vim's `O` command by sending ⌘→ to go to the start of the line,
377 * enter to move the line down, ↑ to move up to the new line, then switching to
380 void VIM_OPEN_ABOVE(void) {
381 print("\e[31mO\e[0m");
386 layer_on(INSERT_MODE);
390 * Vim-like 'change whole line' command
391 * Simulates vim's `S` `cc` or `c$` commands by sending ⌘← to go to the start of the line,
392 * ⌃K to kill the line, then switching to insert mode.
394 void VIM_CHANGE_WHOLE_LINE(void) {
395 print("\e[31mS\e[0m");
402 * ###### ###### ###### ####### ####### ### # # ####### ######
403 * # # # # # # # # # # # # # #
404 * # # # # # # # # # # # # # #
405 * # # ###### ###### ##### ##### # # ##### # #
406 * # # # # # # # # # # # # #
407 * # # # # # # # # # # # # #
408 * ###### # # # ####### # ### # # ####### ######
413 * Vim-like `delete to end` command
414 * Simulates vim's `de` command by sending ⌥⇧→ then ⌘X.
416 void VIM_DELETE_END(void) {
417 print("\e[31me\e[0m");
420 SHIFT(KC_RIGHT); // select to end of this word
426 * Vim-like `delete whole line` command
427 * Simulates vim's `dd` command by sending ⌘← to move to start of line,
428 * selecting the whole line, then sending ⌘X to cut the line.
429 * alternate method: ⌘⌫, ⌃K
431 void VIM_DELETE_WHOLE_LINE(void) {
432 print("\e[31md\e[0m");
442 * Vim-like `delete word` command
443 * Simulates vim's `dw` command by sending ⌥⇧→→← then ⌘X to select to the start
444 * of the next word then cut.
446 void VIM_DELETE_WORD(void) {
447 print("\e[31mw\e[0m");
450 SHIFT(KC_RIGHT); // select to end of this word
451 SHIFT(KC_RIGHT); // select to end of next word
452 SHIFT(KC_LEFT); // select to start of next word
454 CMD(KC_X); // delete selection
458 * Vim-like `delete back` command
459 * Simulates vim's `db` command by selecting to the end of the word then deleting.
461 void VIM_DELETE_BACK(void) {
462 print("\e[31mb\e[0m");
465 SHIFT(KC_LEFT); // select to start of word
466 SHIFT(KC_DEL); // delete selection
471 * Vim-like `delete left` command
472 * Simulates vim's `dh` command by sending ⇧← then ⌘X.
474 void VIM_DELETE_LEFT(void) {
475 print("\e[31mh\e[0m");
482 * Vim-like `delete right` command
483 * Simulates vim's `dl` command by sending ⇧→ then ⌘X.
485 void VIM_DELETE_RIGHT(void) {
486 print("\e[31ml\e[0m");
493 * Vim-like `delete up` command
494 * Simulates vim's `dk` command by sending ↑ then deleting the line.
496 void VIM_DELETE_UP(void) {
497 print("\e[31mk\e[0m");
504 * Vim-like `delete down` command
505 * Simulates vim's `dj` command by sending ↓ then deleting the line.
507 void VIM_DELETE_DOWN(void) {
508 print("\e[31mj\e[0m");
515 * ###### ### ###### ###### ####### ####### ### # # ####### ######
516 * # # # # # # # # # # # # # # #
517 * # # # # # # # # # # # # # # #
518 * # # # ###### ###### ##### ##### # # ##### # #
519 * # # # # # # # # # # # # # #
520 * # # # # # # # # # # # # # #
521 * ###### ### # # # ####### # ### # # ####### ######
526 * Vim-like `delete inner word` command
527 * Simulates vim's `diw` command by moving back then cutting to the end of the word.
529 void VIM_DELETE_INNER_WORD(void) {
530 print("\e[31mw\e[0m");
537 * ##### ###### ###### ####### ####### ### # # ####### ######
538 * # # # # # # # # # # # # # #
539 * # # # # # # # # # # # # #
540 * # ###### ###### ##### ##### # # ##### # #
541 * # # # # # # # # # # # #
542 * # # # # # # # # # # # # #
543 * ##### # # # ####### # ### # # ####### ######
548 * Vim-like `change back` command
549 * Simulates vim's `cb` command by first deleting to the start of the word,
550 * then switching to insert mode.
552 void VIM_CHANGE_BACK(void) {
553 print("\e[31mb\e[0m");
556 layer_on(INSERT_MODE);
560 * Vim-like `change down` command
561 * Simulates vim's `cj` command by sending ↓ then changing the line.
563 void VIM_CHANGE_DOWN(void) {
564 print("\e[31mj\e[0m");
567 layer_on(INSERT_MODE);
571 * Vim-like `change to end` command
572 * Simulates vim's `ce` command by first deleting to the end of the word,
573 * then switching to insert mode.
575 void VIM_CHANGE_END(void) {
576 print("\e[31mce\e[0m");
579 layer_on(INSERT_MODE);
583 * Vim-like `change left` command
584 * Simulates vim's `ch` command by deleting left then switching to insert mode.
586 void VIM_CHANGE_LEFT(void) {
587 print("\e[31mch\e[0m");
590 layer_on(INSERT_MODE);
594 * Vim-like `change right` command
595 * Simulates vim's `cl` command by deleting right then switching to insert mode.
597 void VIM_CHANGE_RIGHT(void) {
598 print("\e[31mcl\e[0m");
600 layer_on(INSERT_MODE);
604 * Vim-like `change up` command
605 * Simulates vim's `ck` command by deleting up then switching to insert mode.
607 void VIM_CHANGE_UP(void) {
608 print("\e[31mck\e[0m");
610 layer_on(INSERT_MODE);
614 * Vim-like `change word` command
615 * Simulates vim's `cw` command by first deleting to the end of the word,
616 * then switching to insert mode.
618 void VIM_CHANGE_WORD(void) {
619 print("\e[31mcw\e[0m");
622 layer_on(INSERT_MODE);
626 * ##### ### ###### ###### ####### ####### ### # # ####### ######
627 * # # # # # # # # # # # # # # #
628 * # # # # # # # # # # # # # #
629 * # # ###### ###### ##### ##### # # ##### # #
630 * # # # # # # # # # # # # #
631 * # # # # # # # # # # # # # #
632 * ##### ### # # # ####### # ### # # ####### ######
637 * Vim-like `change inner word` command
638 * Simulates vim's `ciw` command by deleting the inner word then switching to insert mode.
640 void VIM_CHANGE_INNER_WORD(void) {
641 print("\e[31mciw\e[0m");
642 VIM_DELETE_INNER_WORD();
643 layer_on(INSERT_MODE);
647 * # # ###### ###### ####### ####### ### # # ####### ######
648 * # # # # # # # # # # # # # #
649 * # # # # # # # # # # # # # #
650 * # # ###### ###### ##### ##### # # ##### # #
651 * # # # # # # # # # # # # #
652 * # # # # # # # # # # # # #
653 * # # # # ####### # ### # # ####### ######
658 * Vim-like `visual select back` command
659 * Simulates vim's `vb` command by selecting to the enc of the word.
661 void VIM_VISUAL_BACK(void) {
662 print("\e[31mvb\e[0m");
665 SHIFT(KC_LEFT); // select to start of word
670 * Vim-like `visual select to end` command
671 * Simulates vim's `ve` command by selecting to the end of the word.
673 void VIM_VISUAL_END(void) {
674 print("\e[31mve\e[0m");
677 SHIFT(KC_RIGHT); // select to end of this word
682 * Vim-like `visual select word` command
683 * Simulates vim's `vw` command by selecting to the end of the word.
685 void VIM_VISUAL_WORD(void) {
686 print("\e[31mvw\e[0m");
689 SHIFT(KC_RIGHT); // select to end of this word
690 SHIFT(KC_RIGHT); // select to end of next word
691 SHIFT(KC_LEFT); // select to start of next word
696 * Vim-like `visual left` command
697 * Simulates vim's `vh` command by sending ⇧←.
699 void VIM_VISUAL_LEFT(void) {
700 print("\e[31mvh\e[0m");
706 * Vim-like `visual right` command
707 * Simulates vim's `vl` command by sending ⇧→.
709 void VIM_VISUAL_RIGHT(void) {
710 print("\e[31mvl\e[0m");
716 * Vim-like `visual up` command
717 * Simulates vim's `vk` command by sending ⇧↑.
719 void VIM_VISUAL_UP(void) {
720 print("\e[31mvk\e[0m");
726 * Vim-like `visual down` command
727 * Simulates vim's `vj` command by sending ⇧↓.
729 void VIM_VISUAL_DOWN(void) {
730 print("\e[31mdj\e[0m");
736 * # # ### ###### ###### ####### ####### ### # # ####### ######
737 * # # # # # # # # # # # # # # #
738 * # # # # # # # # # # # # # # #
739 * # # # ###### ###### ##### ##### # # ##### # #
740 * # # # # # # # # # # # # # #
741 * # # # # # # # # # # # # # #
742 * # ### # # # ####### # ### # # ####### ######
747 * Vim-like `visual inner word` command
748 * Simulates vim's `viw` command by moving back then selecting to the end of the word.
750 void VIM_VISUAL_INNER_WORD(void) {
751 print("\e[31mviw\e[0m");