#include "config.h"
#include "print.h"
#include "keycode.h"
#include "quantum.h"
#include "quantum_keycodes.h"
#define NOR_MOD TO(NORMAL_MODE)
#define INS_MOD TO(INSERT_MODE)
#define PRESS(keycode) register_code16(keycode)
#define RELEASE(keycode) unregister_code16(keycode)
uint16_t VIM_QUEUE = KC_NO;
enum custom_keycodes {
PLACEHOLDER = SAFE_RANGE, VIM_A,
VIM_B,
VIM_C,
VIM_CI,
VIM_D,
VIM_DI,
VIM_E,
VIM_H,
VIM_I,
VIM_J,
VIM_K,
VIM_L,
VIM_O,
VIM_P,
VIM_S,
VIM_U,
VIM_V,
VIM_VI,
VIM_W,
VIM_X,
VIM_Y,
EPRM,
VRSN,
RGB_SLD,
};
void VIM_APPEND(void);
void VIM_APPEND_LINE(void);
void VIM_BACK(void);
void VIM_CHANGE_BACK(void);
void VIM_CHANGE_DOWN(void);
void VIM_CHANGE_END(void);
void VIM_CHANGE_INNER_WORD(void);
void VIM_CHANGE_LEFT(void);
void VIM_CHANGE_LINE(void);
void VIM_CHANGE_RIGHT(void);
void VIM_CHANGE_UP(void);
void VIM_CHANGE_WHOLE_LINE(void);
void VIM_CHANGE_WORD(void);
void VIM_CUT(void);
void VIM_DELETE_BACK(void);
void VIM_DELETE_DOWN(void);
void VIM_DELETE_END(void);
void VIM_DELETE_INNER_WORD(void);
void VIM_DELETE_LEFT(void);
void VIM_DELETE_LINE(void);
void VIM_DELETE_RIGHT(void);
void VIM_DELETE_UP(void);
void VIM_DELETE_WHOLE_LINE(void);
void VIM_DELETE_WORD(void);
void VIM_END(void);
void VIM_JOIN(void);
void VIM_OPEN(void);
void VIM_OPEN_ABOVE(void);
void VIM_PUT(void);
void VIM_SUBSTITUTE(void);
void VIM_UNDO(void);
void VIM_VISUAL_BACK(void);
void VIM_VISUAL_DOWN(void);
void VIM_VISUAL_END(void);
void VIM_VISUAL_INNER_WORD(void);
void VIM_VISUAL_LEFT(void);
void VIM_VISUAL_RIGHT(void);
void VIM_VISUAL_UP(void);
void VIM_VISUAL_WORD(void);
void VIM_WORD(void);
void VIM_YANK(void);
void TAP(uint16_t keycode) {
PRESS(keycode);
RELEASE(keycode);
}
void CMD(uint16_t keycode) {
PRESS(KC_LGUI);
TAP(keycode);
RELEASE(KC_LGUI);
}
void CTRL(uint16_t keycode) {
PRESS(KC_LCTRL);
TAP(keycode);
RELEASE(KC_LCTRL);
}
void SHIFT(uint16_t keycode) {
PRESS(KC_LSHIFT);
TAP(keycode);
RELEASE(KC_LSHIFT);
}
void ALT(uint16_t keycode) {
PRESS(KC_LALT);
TAP(keycode);
RELEASE(KC_LALT);
}
void VIM_LEADER(uint16_t keycode) {
VIM_QUEUE = keycode;
switch(keycode) {
case VIM_C: print("\e[32mc\e[0m"); break;
case VIM_CI: print("\e[32mi\e[0m"); break;
case VIM_D: print("\e[32md\e[0m"); break;
case VIM_DI: print("\e[32mi\e[0m"); break;
case VIM_V: print("\e[32mv\e[0m"); break;
case VIM_VI: print("\e[32mi\e[0m"); break;
case KC_NO: print("❎"); break;
}
}
void VIM_APPEND(void) {
print("\e[31ma\e[0m");
TAP(KC_RIGHT);
layer_on(INSERT_MODE);
}
void VIM_BACK(void) {
print("\e[31mb\e[0m");
ALT(KC_LEFT);
}
void VIM_CUT(void) {
print("\e[31mx\e[0m");
SHIFT(KC_RIGHT);
CMD(KC_X);
}
void VIM_DOWN(void) {
print("\e[31mj\e[0m");
TAP(KC_DOWN);
}
void VIM_END(void) {
print("\e[31me\e[0m");
ALT(KC_RIGHT);
}
void VIM_LEFT(void) {
print("\e[31mh\e[0m");
VIM_LEADER(KC_NO);
TAP(KC_LEFT);
}
void VIM_OPEN(void) {
print("\e[31mo\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_RIGHT);
TAP(KC_ENTER);
layer_on(INSERT_MODE);
}
void VIM_PUT(void) {
print("\e[31mp\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_V);
}
void VIM_PUT_BEFORE(void) {
print("\e[31mP\e[0m");
VIM_LEADER(KC_NO);
TAP(KC_UP);
CMD(KC_LEFT);
CMD(KC_V);
}
void VIM_RIGHT(void) {
print("\e[31ml\e[0m");
VIM_LEADER(KC_NO);
TAP(KC_RIGHT);
}
void VIM_SUBSTITUTE(void) {
print("\e[31ms\e[0m");
VIM_LEADER(KC_NO);
SHIFT(KC_RIGHT);
CMD(KC_X);
layer_on(INSERT_MODE);
}
void VIM_UNDO(void) {
print("\e[31mu\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_Z);
}
void VIM_UP(void) {
print("\e[31mk\e[0m");
VIM_LEADER(KC_NO);
TAP(KC_UP);
}
void VIM_WORD(void) {
print("\e[31mw\e[0m");
VIM_LEADER(KC_NO);
PRESS(KC_LALT);
TAP(KC_RIGHT);
TAP(KC_RIGHT);
TAP(KC_LEFT);
RELEASE(KC_LALT);
}
void VIM_YANK(void) {
print("\e[31my\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_C);
}
void VIM_YANK_LINE(void) {
print("\e[31mY\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_LEFT);
PRESS(KC_LSHIFT);
CMD(KC_RIGHT);
RELEASE(KC_LSHIFT);
CMD(KC_C);
}
void VIM_APPEND_LINE(void) {
print("\e[31mA\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_RIGHT);
layer_on(INSERT_MODE);
}
void VIM_CHANGE_LINE(void) {
print("\e[31mC\e[0m");
VIM_LEADER(KC_NO);
VIM_DELETE_LINE();
layer_on(INSERT_MODE);
}
void VIM_DELETE_LINE(void) {
print("\e[31mD\e[0m");
VIM_LEADER(KC_NO);
CTRL(KC_K);
}
void VIM_JOIN(void) {
print("\e[31mJ\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_RIGHT);
TAP(KC_DELETE);
VIM_LEADER(KC_NO);
}
void VIM_OPEN_ABOVE(void) {
print("\e[31mO\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_LEFT);
TAP(KC_ENTER);
TAP(KC_UP);
layer_on(INSERT_MODE);
}
void VIM_CHANGE_WHOLE_LINE(void) {
print("\e[31mS\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_LEFT);
VIM_CHANGE_LINE();
}
void VIM_DELETE_END(void) {
print("\e[31me\e[0m");
VIM_LEADER(KC_NO);
PRESS(KC_LALT);
SHIFT(KC_RIGHT); RELEASE(KC_LALT);
CMD(KC_X);
}
void VIM_DELETE_WHOLE_LINE(void) {
print("\e[31md\e[0m");
VIM_LEADER(KC_NO);
CMD(KC_LEFT);
PRESS(KC_LSHIFT);
CMD(KC_RIGHT);
RELEASE(KC_LSHIFT);
CMD(KC_X);
}
void VIM_DELETE_WORD(void) {
print("\e[31mw\e[0m");
VIM_LEADER(KC_NO);
PRESS(KC_LALT);
SHIFT(KC_RIGHT); SHIFT(KC_RIGHT); SHIFT(KC_LEFT); RELEASE(KC_LALT);
CMD(KC_X); }
void VIM_DELETE_BACK(void) {
print("\e[31mb\e[0m");
VIM_LEADER(KC_NO);
PRESS(KC_LALT);
SHIFT(KC_LEFT); SHIFT(KC_DEL); RELEASE(KC_LSHIFT);
}
void VIM_DELETE_LEFT(void) {
print("\e[31mh\e[0m");
VIM_LEADER(KC_NO);
SHIFT(KC_LEFT);
CMD(KC_X);
}
void VIM_DELETE_RIGHT(void) {
print("\e[31ml\e[0m");
VIM_LEADER(KC_NO);
SHIFT(KC_RIGHT);
CMD(KC_X);
}
void VIM_DELETE_UP(void) {
print("\e[31mk\e[0m");
VIM_LEADER(KC_NO);
TAP(KC_UP);
VIM_DELETE_LINE();
}
void VIM_DELETE_DOWN(void) {
print("\e[31mj\e[0m");
VIM_LEADER(KC_NO);
TAP(KC_DOWN);
VIM_DELETE_LINE();
}
void VIM_DELETE_INNER_WORD(void) {
print("\e[31mw\e[0m");
VIM_LEADER(KC_NO);
VIM_BACK();
VIM_DELETE_END();
}
void VIM_CHANGE_BACK(void) {
print("\e[31mb\e[0m");
VIM_LEADER(KC_NO);
VIM_DELETE_BACK();
layer_on(INSERT_MODE);
}
void VIM_CHANGE_DOWN(void) {
print("\e[31mj\e[0m");
VIM_LEADER(KC_NO);
VIM_DELETE_DOWN();
layer_on(INSERT_MODE);
}
void VIM_CHANGE_END(void) {
print("\e[31mce\e[0m");
VIM_LEADER(KC_NO);
VIM_DELETE_END();
layer_on(INSERT_MODE);
}
void VIM_CHANGE_LEFT(void) {
print("\e[31mch\e[0m");
VIM_LEADER(KC_NO);
VIM_DELETE_LEFT();
layer_on(INSERT_MODE);
}
void VIM_CHANGE_RIGHT(void) {
print("\e[31mcl\e[0m");
VIM_DELETE_RIGHT();
layer_on(INSERT_MODE);
}
void VIM_CHANGE_UP(void) {
print("\e[31mck\e[0m");
VIM_DELETE_UP();
layer_on(INSERT_MODE);
}
void VIM_CHANGE_WORD(void) {
print("\e[31mcw\e[0m");
VIM_LEADER(KC_NO);
VIM_DELETE_WORD();
layer_on(INSERT_MODE);
}
void VIM_CHANGE_INNER_WORD(void) {
print("\e[31mciw\e[0m");
VIM_DELETE_INNER_WORD();
layer_on(INSERT_MODE);
}
void VIM_VISUAL_BACK(void) {
print("\e[31mvb\e[0m");
VIM_LEADER(KC_NO);
PRESS(KC_LALT);
SHIFT(KC_LEFT); RELEASE(KC_LALT);
}
void VIM_VISUAL_END(void) {
print("\e[31mve\e[0m");
VIM_LEADER(KC_NO);
PRESS(KC_LALT);
SHIFT(KC_RIGHT); RELEASE(KC_LALT);
}
void VIM_VISUAL_WORD(void) {
print("\e[31mvw\e[0m");
VIM_LEADER(KC_NO);
PRESS(KC_LALT);
SHIFT(KC_RIGHT); SHIFT(KC_RIGHT); SHIFT(KC_LEFT); RELEASE(KC_LALT);
}
void VIM_VISUAL_LEFT(void) {
print("\e[31mvh\e[0m");
VIM_LEADER(KC_NO);
SHIFT(KC_LEFT);
}
void VIM_VISUAL_RIGHT(void) {
print("\e[31mvl\e[0m");
VIM_LEADER(KC_NO);
SHIFT(KC_RIGHT);
}
void VIM_VISUAL_UP(void) {
print("\e[31mvk\e[0m");
VIM_LEADER(KC_NO);
SHIFT(KC_UP);
}
void VIM_VISUAL_DOWN(void) {
print("\e[31mdj\e[0m");
VIM_LEADER(KC_NO);
SHIFT(KC_DOWN);
}
void VIM_VISUAL_INNER_WORD(void) {
print("\e[31mviw\e[0m");
VIM_LEADER(KC_NO);
VIM_BACK();
VIM_VISUAL_END();
}