1
0
Fork 0

Xton's first keymap! (#2941)

* FORK!

* WIP - just how i like it

* empty

* more movement

* mouse keys

* more vimminess

* append/insert shift

* WIP - vim macros

* blocked out layer below in cmd mode.

also, about to restart my cmd approach.

* WIP - new vim layer

ripoff of the ergodox one, but rewritten as a state machine.

* debugged some, got key repeat working

* moooar coverage

* moooar coverage

* regular vis mode

* basically done with basics.

* some refactoring

- common movement sequences into helper function
- added some rgb controls

* modkey passthru feature

* stdized on cmd-left/right instead of ctrl-a/e

sadly. as there's no reliable shift-ctrl-e

* indicator lights

* moved vim layer into userspace

* cleaned up some yanking edge cases

* docs and some tweaks to layerescapes

* updated/added license strings

* updated comments

* moved config changes to keymap

* spurious changes removed
This commit is contained in:
xton 2018-05-12 08:52:11 -07:00 committed by Drashna Jaelre
parent 5b503cc543
commit 05be1de1aa
10 changed files with 952 additions and 1 deletions

View file

@ -14,4 +14,4 @@
"*.hpp": "cpp", "*.hpp": "cpp",
"xstddef": "c" "xstddef": "c"
} }
} }

View file

@ -21,3 +21,4 @@ When adding your keymap to this list, keep it organised alphabetically (select l
- **default** default layout from KBDFans - **default** default layout from KBDFans
- **mason** - **mason**
- **planck** Planck default layout - **planck** Planck default layout
- **xtonhasvim** A Planck-like layout with a few tweaks and a vim emulation layer.

View file

@ -0,0 +1,49 @@
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
#include "../../config.h"
#define MUSIC_MASK (keycode != KC_NO)
/*
* MIDI options
*/
/* Prevent use of disabled MIDI features in the keymap */
//#define MIDI_ENABLE_STRICT 1
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
#define MIDI_BASIC
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
- Octave shift and transpose
- Virtual sustain, portamento, and modulation wheel
- etc.
*/
//#define MIDI_ADVANCED
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
//#define MIDI_TONE_KEYCODE_OCTAVES 2
// help for fast typist+dual function keys?
#define PERMISSIVE_HOLD
/* disable debug print */
#define NO_DEBUG
/* disable print */
#define NO_PRINT
/* speed up mousekeys a bit */
#define MOUSEKEY_DELAY 50
#define MOUSEKEY_INTERVAL 20
#define MOUSEKEY_MAX_SPEED 8
#define MOUSEKEY_TIME_TO_MAX 30
#define MOUSEKEY_WHEEL_MAX_SPEED 8
#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
#endif

View file

@ -0,0 +1,210 @@
/* Copyright 2015-2017 Christon DeWan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include QMK_KEYBOARD_H
#include "action_layer.h"
#include "xtonhasvim.h"
/************************************
* states
************************************/
enum layers {
_QWERTY,
_LOWER,
_RAISE,
_ADJUST,
_MOVE,
_MOUSE
};
/************************************
* keymaps!
************************************/
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Qwerty
* ,-----------------------------------------------------------------------------------.
* | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Ctrl*| A* | S | D | F | G | H | J | K | L | ;* | " |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | Mouse| | Alt | GUI |Lower*| Space |Raise*| GUI | Alt | | Vim |
* `-----------------------------------------------------------------------------------'
*
* - Ctrl acts as Esc when tapped.
* - Holding A or ; switches to movement layer.
* - Raise and Lower are one-shot layers.
*/
[_QWERTY] = {
{KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
{LCTL_T(KC_ESC), LT(_MOVE,KC_A), KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(_MOVE,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, RSFT_T(KC_ENT) },
{TG(_MOUSE), X_____X, KC_LALT, KC_LGUI, OSL(_LOWER), KC_SPC, KC_SPC, OSL(_RAISE), KC_LGUI, KC_LALT, X_____X, VIM_START }
},
/* Lower
* ,-----------------------------------------------------------------------------------.
* | ~ | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Del | ! | @ | # | $ | % | ^ | & | * | ( | ) | | |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | | F7 | F8 | F9 | F10 | F11 | F12 | | | Home | End | |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | | | | | | | | Next | Vol- | Vol+ | Play |
* `-----------------------------------------------------------------------------------'
*/
[_LOWER] = {
{KC_TILD, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_BSPC},
{KC_DEL, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_PIPE},
{_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, KC_HOME, KC_END, _______},
{_______, TO(_QWERTY), _______, _______, _______, _______, _______, OSL(_ADJUST), KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
},
/* Raise
* ,-----------------------------------------------------------------------------------.
* | ` | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | Bksp |
* |------+------+------+------+------+-------------+------+------+------+------+------|
* | Del | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | \ |
* |------+------+------+------+------+------|------+------+------+------+------+------|
* | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | |
* |------+------+------+------+------+------+------+------+------+------+------+------|
* | | | | | | | | Next | Vol- | Vol+ | Play |
* `-----------------------------------------------------------------------------------'
*/
[_RAISE] = {
{KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSPC},
{KC_DEL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSLS},
{_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, KC_PGUP, KC_PGDN, _______},
{_______, TO(_QWERTY), _______, _______, OSL(_ADJUST), _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
},
/* Adjust (Lower + Raise)
* ,-------------------------------------------------------------------------------------.
* |RGBPlain| Reset| | | | | | | | | | Del |
* |--------+------+------+------+------+-------------+------+------+------+------+------|
* |RGBMode-| | |Aud on|Audoff|AGnorm|AGswap| | | | |Lite+ |
* |--------+------+------+------+------+------|------+------+------+------+------+------|
* |RGBMode+|Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | |Lite- |
* |--------+------+------+------+------+------+------+------+------+------+------+------|
* | RGB | | | | | | | | | | |
* `-------------------------------------------------------------------------------------'
*/
[_ADJUST] = {
{RGB_MODE_PLAIN, RESET, DEBUG, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL },
{RGB_MODE_REVERSE, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, RGB_VAI},
{RGB_MODE_FORWARD, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, RGB_VAD},
{RGB_TOG, TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
},
/* movement layer (hold semicolon)
*/
[_MOVE] = {
{TO(_QWERTY), X_____X, X_____X, X_____X, X_____X, X_____X, KC_HOME, KC_PGDN, KC_PGUP, KC_END, X_____X, X_____X},
{_______, X_____X, LGUI(KC_LBRC), LGUI(LSFT(KC_LBRC)), LGUI(LSFT(KC_RBRC)), LGUI(KC_RBRC), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, X_____X, X_____X},
{_______, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, _______},
{X_____X, TO(_QWERTY), _______, _______, _______, X_____X, X_____X, _______, _______, _______, TO(_QWERTY), _______}
},
/* mouse layer
*/
[_MOUSE] = {
{TO(_QWERTY), X_____X, X_____X, KC_MS_UP, X_____X, X_____X, KC_MS_WH_LEFT, KC_MS_WH_DOWN, KC_MS_WH_UP, KC_MS_WH_RIGHT, X_____X, X_____X },
{_______, X_____X, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT, X_____X, X_____X, KC_MS_BTN1, KC_MS_BTN2, KC_MS_BTN3, X_____X, X_____X},
{_______, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, _______},
{_______, TO(_QWERTY), _______, _______, _______, X_____X, X_____X, _______, _______, _______, TO(_QWERTY), _______}
},
/* vim edit mode. just has an escape -> _CMD key */
[_EDIT] = {
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
{VIM_START, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
{_______, TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, TO(_QWERTY), _______}
},
/* vim command layer.
*/
[_CMD] = {
{X_____X, X_____X, VIM_W, VIM_E, X_____X, X_____X, VIM_Y, VIM_U, VIM_I, VIM_O, VIM_P, X_____X},
{VIM_ESC, VIM_A, VIM_S, VIM_D, X_____X, VIM_G, VIM_H, VIM_J, VIM_K, VIM_L, X_____X, X_____X},
{VIM_SHIFT, X_____X, VIM_X, VIM_C, VIM_V, VIM_B, X_____X, X_____X, VIM_COMMA, VIM_PERIOD, X_____X, VIM_SHIFT},
{X_____X, TO(_QWERTY), _______, _______, X_____X, X_____X, X_____X, X_____X, _______, _______, TO(_QWERTY), X_____X}
}
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if(process_record_xtonhasvim(keycode, record)) {
// do nothing so far
return true;
} else {
// already handled by vim
return false;
}
}
/** Set just 4 LEDs closest to the user. Slightly less annoying to bystanders.*/
void rgbflag(uint8_t r, uint8_t g, uint8_t b) {
for(int i = 0; i < RGBLED_NUM; i++){
switch(i) {
case 9 ... 12:
// rgblight_setrgb_at(r,g,b,i);
led[i].r = r;
led[i].g = g;
led[i].b = b;
break;
default:
// rgblight_setrgb_at(0,0,0,i);
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
break;
}
}
rgblight_set();
}
uint32_t layer_state_set_user(uint32_t state) {
if(rgblight_get_mode() == 1) {
switch (biton32(state)) {
case _RAISE:
case _LOWER:
case _ADJUST:
rgbflag(0x00, 0x00, 0xFF);
break;
case _MOVE:
case _MOUSE:
rgbflag(0xFF, 0x00, 0x00);
break;
case _CMD:
rgbflag(0x00, 0xFF, 0x00);
break;
case _EDIT:
rgbflag(0x7A, 0x00, 0xFF);
break;
default: // for any other layers, or the default layer
rgbflag(0x00, 0xFF, 0xFF);
break;
}
}
return state;
}

View file

@ -0,0 +1,9 @@
# Xton has a tiny keyboard! With Vim!
Based on the standard Planck layout with a few changes:
* Escape moved to dual-function with control.
* Dedicated movement and mouse layers.
* Top and middle row swapped in `_RAISE` and `_LOWER` because I never use F-keys.
* Vim layers! See `users/xtonhasvim`.

View file

@ -0,0 +1,6 @@
ifndef QUANTUM_DIR
include ../../../../Makefile
endif
MOUSEKEY_ENABLE = yes
BACKLIGHT_ENABLE = no

View file

@ -0,0 +1,10 @@
# Xton has Vim!
Contains common code for Xton's vim emulation (vimulation?) layer.
Inspired/stolen from the `ergodox_ez/vim` keymap. Rewritten to be a more straightforward state machine and support more macros. Vim layers `_CMD` and `_EDIT` are designed to lay on top of an otherwise fully-functional layout. `_CMD` runs the entire vim state machine while `_EDIT` should lay across your base layer and mask off just the escape key.
Works via OSX text editing shortcuts, mainly MOD+arrow combinations. This has some limitations and only works on OSX.
The `_CMD` layer will temporarily disable itself while *CMD* or *ALT* are held down so that typical OSX shortcuts can be used without switching out of vim mode.

View file

@ -0,0 +1 @@
SRC += xtonhasvim.c

View file

@ -0,0 +1,599 @@
/* Copyright 2015-2017 Christon DeWan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "xtonhasvim.h"
/************************************
* helper foo
************************************/
#define PRESS(kc) register_code(kc)
#define RELEASE(kc) unregister_code(kc)
static void TAP(uint16_t keycode) {
PRESS(keycode);
RELEASE(keycode);
}
static void CMD(uint16_t keycode) {
PRESS(KC_LGUI);
TAP(keycode);
RELEASE(KC_LGUI);
}
static void CTRL(uint16_t keycode) {
PRESS(KC_LCTRL);
TAP(keycode);
RELEASE(KC_LCTRL);
}
static void SHIFT(uint16_t keycode) {
PRESS(KC_LSHIFT);
TAP(keycode);
RELEASE(KC_LSHIFT);
}
static void ALT(uint16_t keycode) {
PRESS(KC_LALT);
TAP(keycode);
RELEASE(KC_LALT);
}
uint16_t vstate = VIM_START;
bool yank_was_lines = false;
bool SHIFTED = false;
uint32_t mod_override_layer_state = 0;
uint16_t mod_override_triggering_key = 0;
bool do_check_kb_clear = false;
void vim_reset(void) {
vstate = VIM_START;
SHIFTED = false;
yank_was_lines = false;
}
void edit(void) { vstate = VIM_START; layer_on(_EDIT); layer_off(_CMD); }
#define EDIT edit()
void simple_movement(uint16_t keycode) {
switch(keycode) {
case VIM_B:
PRESS(KC_LALT);
SHIFT(KC_LEFT); // select to start of this word
RELEASE(KC_LALT);
break;
case VIM_E:
PRESS(KC_LALT);
SHIFT(KC_RIGHT); // select to end of this word
RELEASE(KC_LALT);
break;
case VIM_H:
SHIFT(KC_LEFT);
break;
case VIM_J:
CMD(KC_LEFT);
SHIFT(KC_DOWN);
SHIFT(KC_DOWN);
break;
case VIM_K:
CMD(KC_LEFT);
TAP(KC_DOWN);
SHIFT(KC_UP);
SHIFT(KC_UP);
break;
case VIM_L:
SHIFT(KC_RIGHT);
break;
case VIM_W:
PRESS(KC_LALT);
SHIFT(KC_RIGHT); // select to end of this word
SHIFT(KC_RIGHT); // select to end of next word
SHIFT(KC_LEFT); // select to start of next word
RELEASE(KC_LALT);
break;
}
}
bool process_record_xtonhasvim(uint16_t keycode, keyrecord_t *record) {
if(record->event.pressed && layer_state_is(_CMD) && IS_MOD(keycode)) {
mod_override_layer_state = layer_state;
mod_override_triggering_key = keycode;
layer_clear();
return true; // let the event fall through...
}
if(mod_override_layer_state && !record->event.pressed && keycode == mod_override_triggering_key) {
layer_state_set(mod_override_layer_state);
mod_override_layer_state = 0;
mod_override_triggering_key = 0;
return true;
}
if (VIM_START <= keycode && keycode <= VIM_ESC) {
if(keycode == VIM_SHIFT) {
SHIFTED = record->event.pressed;
return false;
}
if (record->event.pressed) {
if(keycode == VIM_START) {
// entry from anywhere
layer_on(_CMD);
vstate = VIM_START;
return false;
}
switch(vstate) {
case VIM_START:
switch(keycode){
/*****************************
* ground state
*****************************/
case VIM_A:
if(SHIFTED) {
// CMD(KC_RIGHT);
CTRL(KC_E);
} else {
TAP(KC_RIGHT);
}
EDIT;
break;
case VIM_B:
PRESS(KC_LALT);
PRESS(KC_LEFT);
break;
case VIM_C:
if(SHIFTED) {
PRESS(KC_LSHIFT);
CMD(KC_RIGHT);
RELEASE(KC_LSHIFT);
CMD(KC_X);
yank_was_lines = false;
EDIT;
} else {
vstate = VIM_C;
}
break;
case VIM_D:
if(SHIFTED) {
TAP(KC_K);
} else {
vstate = VIM_D;
}
break;
case VIM_E:
PRESS(KC_LALT);
PRESS(KC_RIGHT);
break;
case VIM_G:
if(SHIFTED) {
TAP(KC_END);
} else {
vstate = VIM_G;
}
break;
case VIM_H:
PRESS(KC_LEFT);
break;
case VIM_I:
if(SHIFTED){
CTRL(KC_A);
}
EDIT;
break;
case VIM_J:
if(SHIFTED) {
CMD(KC_RIGHT);
TAP(KC_DEL);
} else {
PRESS(KC_DOWN);
}
break;
case VIM_K:
PRESS(KC_UP);
break;
case VIM_L:
PRESS(KC_RIGHT);
break;
case VIM_O:
if(SHIFTED) {
CMD(KC_LEFT);
TAP(KC_ENTER);
TAP(KC_UP);
EDIT;
} else {
CMD(KC_RIGHT);
TAP(KC_ENTER);
EDIT;
}
break;
case VIM_P:
if(SHIFTED) {
CMD(KC_LEFT);
CMD(KC_V);
} else {
if(yank_was_lines) {
CMD(KC_RIGHT);
TAP(KC_RIGHT);
CMD(KC_V);
} else {
CMD(KC_V);
}
}
break;
case VIM_S:
// s for substitute?
if(SHIFTED) {
CMD(KC_LEFT);
PRESS(KC_LSHIFT);
CMD(KC_RIGHT);
RELEASE(KC_LSHIFT);
CMD(KC_X);
yank_was_lines = false;
EDIT;
} else {
SHIFT(KC_RIGHT);
CMD(KC_X);
yank_was_lines = false;
EDIT;
}
break;
case VIM_U:
if(SHIFTED) {
PRESS(KC_LSFT);
CMD(KC_Z);
RELEASE(KC_LSHIFT);
} else {
CMD(KC_Z);
}
break;
case VIM_V:
if(SHIFTED) {
CMD(KC_LEFT);
SHIFT(KC_DOWN);
vstate = VIM_VS;
} else {
vstate = VIM_V;
}
break;
case VIM_W:
PRESS(KC_LALT);
TAP(KC_RIGHT);
TAP(KC_RIGHT);
TAP(KC_LEFT);
RELEASE(KC_LALT);
break;
case VIM_X:
// SHIFT(KC_RIGHT);
// CMD(KC_X);
PRESS(KC_DEL);
break;
case VIM_Y:
if(SHIFTED) {
CMD(KC_LEFT);
SHIFT(KC_DOWN);
CMD(KC_C);
TAP(KC_RIGHT);
yank_was_lines = true;
} else {
vstate = VIM_Y;
}
break;
case VIM_COMMA:
if(SHIFTED) {
// indent
CMD(KC_LBRACKET);
} else {
// toggle comment
CMD(KC_SLASH);
}
break;
case VIM_PERIOD:
if(SHIFTED) {
// outdent
CMD(KC_RBRACKET);
}
break;
}
break;
case VIM_C:
/*****************************
* c- ...for change. I never use this...
*****************************/
switch(keycode) {
case VIM_B:
case VIM_E:
case VIM_H:
case VIM_J:
case VIM_K:
case VIM_L:
case VIM_W:
simple_movement(keycode);
CMD(KC_X);
yank_was_lines = false;
EDIT;
break;
case VIM_C:
CMD(KC_LEFT);
PRESS(KC_LSHIFT);
CMD(KC_RIGHT);
RELEASE(KC_LSHIFT);
CMD(KC_X);
yank_was_lines = false;
EDIT;
break;
case VIM_I:
vstate = VIM_CI;
break;
default:
vstate = VIM_START;
break;
}
break;
case VIM_CI:
/*****************************
* ci- ...change inner word
*****************************/
switch(keycode) {
case VIM_W:
ALT(KC_LEFT);
PRESS(KC_LSHIFT);
ALT(KC_RIGHT);
RELEASE(KC_LSHIFT);
CMD(KC_X);
yank_was_lines = false;
EDIT;
default:
vstate = VIM_START;
break;
}
break;
case VIM_D:
/*****************************
* d- ...delete stuff
*****************************/
switch(keycode) {
case VIM_B:
case VIM_E:
case VIM_H:
case VIM_J:
case VIM_K:
case VIM_L:
case VIM_W:
simple_movement(keycode);
CMD(KC_X);
yank_was_lines = false;
break;
case VIM_D:
CMD(KC_LEFT);
SHIFT(KC_DOWN);
CMD(KC_X);
yank_was_lines = true;
vstate = VIM_START;
break;
case VIM_I:
vstate = VIM_DI;
break;
default:
vstate = VIM_START;
break;
}
break;
case VIM_DI:
/*****************************
* ci- ...delete a word... FROM THE INSIDE!
*****************************/
switch(keycode) {
case VIM_W:
ALT(KC_LEFT);
PRESS(KC_LSHIFT);
ALT(KC_RIGHT);
RELEASE(KC_LSHIFT);
CMD(KC_X);
yank_was_lines = false;
vstate = VIM_START;
default:
vstate = VIM_START;
break;
}
break;
case VIM_V:
/*****************************
* visual!
*****************************/
switch(keycode) {
case VIM_D:
case VIM_X:
CMD(KC_X);
yank_was_lines = false;
vstate = VIM_START;
break;
case VIM_B:
PRESS(KC_LALT);
PRESS(KC_LSHIFT);
PRESS(KC_LEFT);
// leave open for key repeat
break;
case VIM_E:
PRESS(KC_LALT);
PRESS(KC_LSHIFT);
PRESS(KC_RIGHT);
// leave open for key repeat
break;
case VIM_H:
PRESS(KC_LSHIFT);
PRESS(KC_LEFT);
break;
case VIM_I:
vstate = VIM_VI;
break;
case VIM_J:
PRESS(KC_LSHIFT);
PRESS(KC_DOWN);
break;
case VIM_K:
PRESS(KC_LSHIFT);
PRESS(KC_UP);
break;
case VIM_L:
PRESS(KC_LSHIFT);
PRESS(KC_RIGHT);
break;
case VIM_W:
PRESS(KC_LALT);
SHIFT(KC_RIGHT); // select to end of this word
SHIFT(KC_RIGHT); // select to end of next word
SHIFT(KC_LEFT); // select to start of next word
RELEASE(KC_LALT);
break;
case VIM_Y:
CMD(KC_C);
TAP(KC_RIGHT);
yank_was_lines = false;
vstate = VIM_START;
break;
case VIM_V:
case VIM_ESC:
TAP(KC_RIGHT);
vstate = VIM_START;
break;
default:
// do nothing
break;
}
break;
case VIM_VI:
/*****************************
* vi- ...select a word... FROM THE INSIDE!
*****************************/
switch(keycode) {
case VIM_W:
ALT(KC_LEFT);
PRESS(KC_LSHIFT);
ALT(KC_RIGHT);
RELEASE(KC_LSHIFT);
vstate = VIM_V;
default:
// ignore
vstate = VIM_V;
break;
}
break;
case VIM_VS:
/*****************************
* visual line
*****************************/
switch(keycode) {
case VIM_D:
case VIM_X:
CMD(KC_X);
yank_was_lines = true;
vstate = VIM_START;
break;
case VIM_J:
PRESS(KC_LSHIFT);
PRESS(KC_DOWN);
break;
case VIM_K:
PRESS(KC_LSHIFT);
PRESS(KC_UP);
break;
case VIM_Y:
CMD(KC_C);
yank_was_lines = true;
TAP(KC_RIGHT);
vstate = VIM_START;
break;
case VIM_V:
case VIM_ESC:
TAP(KC_RIGHT);
vstate = VIM_START;
break;
default:
// do nothing
break;
}
break;
case VIM_G:
/*****************************
* gg, and a grab-bag of other macros i find useful
*****************************/
switch(keycode) {
case VIM_G:
TAP(KC_HOME);
break;
// codes b
case VIM_H:
CTRL(KC_A);
break;
case VIM_J:
PRESS(KC_PGDN);
break;
case VIM_K:
PRESS(KC_PGUP);
break;
case VIM_L:
CTRL(KC_E);
break;
default:
// do nothing
break;
}
vstate = VIM_START;
break;
case VIM_Y:
/*****************************
* yoink!
*****************************/
switch(keycode) {
case VIM_B:
case VIM_E:
case VIM_H:
case VIM_J:
case VIM_K:
case VIM_L:
case VIM_W:
simple_movement(keycode);
CMD(KC_C);
TAP(KC_RIGHT);
yank_was_lines = false;
break;
case VIM_Y:
CMD(KC_LEFT);
SHIFT(KC_DOWN);
CMD(KC_C);
TAP(KC_RIGHT);
yank_was_lines = true;
break;
default:
// NOTHING
break;
}
vstate = VIM_START;
break;
}
} else {
/************************
* key release events
************************/
clear_keyboard();
}
return false;
} else {
return true;
}
}

View file

@ -0,0 +1,66 @@
/* Copyright 2015-2017 Christon DeWan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERSPACE
#define USERSPACE
#include QMK_KEYBOARD_H
#include "action_layer.h"
#define X_____X KC_NO
bool process_record_xtonhasvim(uint16_t keycode, keyrecord_t *record);
enum xtonhasvim_keycodes {
DUMMY = SAFE_RANGE,
VIM_START, // bookend for vim states
VIM_A,
VIM_B,
VIM_C,
VIM_CI,
VIM_D,
VIM_DI,
VIM_E,
VIM_H,
VIM_G,
VIM_I,
VIM_J,
VIM_K,
VIM_L,
VIM_O,
VIM_P,
VIM_S,
VIM_U,
VIM_V,
VIM_VS, // visual-line
VIM_VI,
VIM_W,
VIM_X,
VIM_Y,
VIM_PERIOD, // to support indent/outdent
VIM_COMMA, // and toggle comments
VIM_SHIFT, // avoid side-effect of supporting real shift.
VIM_ESC, // bookend
VIM_SAFE_RANGE // start other keycodes here.
};
enum xtonhasvim_layers {
_EDIT = 12,
_CMD
};
#endif