Browse Source

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
pjones-keymap
xton 1 year ago
parent
commit
05be1de1aa

+ 1
- 1
.vscode/settings.json View File

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

+ 1
- 0
keyboards/niu_mini/keymaps/readme.md View File

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

+ 49
- 0
keyboards/niu_mini/keymaps/xtonhasvim/config.h View File

@@ -0,0 +1,49 @@
1
+#ifndef CONFIG_USER_H
2
+#define CONFIG_USER_H
3
+
4
+#include "../../config.h"
5
+
6
+#define MUSIC_MASK (keycode != KC_NO)
7
+
8
+/*
9
+ * MIDI options
10
+ */
11
+
12
+/* Prevent use of disabled MIDI features in the keymap */
13
+//#define MIDI_ENABLE_STRICT 1
14
+
15
+/* enable basic MIDI features:
16
+   - MIDI notes can be sent when in Music mode is on
17
+*/
18
+
19
+#define MIDI_BASIC
20
+
21
+/* enable advanced MIDI features:
22
+   - MIDI notes can be added to the keymap
23
+   - Octave shift and transpose
24
+   - Virtual sustain, portamento, and modulation wheel
25
+   - etc.
26
+*/
27
+//#define MIDI_ADVANCED
28
+
29
+/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
30
+//#define MIDI_TONE_KEYCODE_OCTAVES 2
31
+
32
+// help for fast typist+dual function keys?
33
+#define PERMISSIVE_HOLD
34
+
35
+/* disable debug print */
36
+#define NO_DEBUG
37
+
38
+/* disable print */
39
+#define NO_PRINT
40
+
41
+/* speed up mousekeys a bit */
42
+#define MOUSEKEY_DELAY             50
43
+#define MOUSEKEY_INTERVAL          20
44
+#define MOUSEKEY_MAX_SPEED         8
45
+#define MOUSEKEY_TIME_TO_MAX       30
46
+#define MOUSEKEY_WHEEL_MAX_SPEED   8
47
+#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
48
+
49
+#endif

+ 210
- 0
keyboards/niu_mini/keymaps/xtonhasvim/keymap.c View File

@@ -0,0 +1,210 @@
1
+ /* Copyright 2015-2017 Christon DeWan
2
+ *
3
+ * This program is free software: you can redistribute it and/or modify
4
+ * it under the terms of the GNU General Public License as published by
5
+ * the Free Software Foundation, either version 2 of the License, or
6
+ * (at your option) any later version.
7
+ *
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+ * GNU General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
+ */
16
+
17
+#include QMK_KEYBOARD_H
18
+#include "action_layer.h"
19
+#include "xtonhasvim.h"
20
+
21
+/************************************
22
+ * states
23
+ ************************************/
24
+
25
+enum layers {
26
+  _QWERTY,
27
+  _LOWER,
28
+  _RAISE,
29
+  _ADJUST,
30
+  _MOVE,
31
+  _MOUSE
32
+};
33
+
34
+/************************************
35
+ * keymaps!
36
+ ************************************/
37
+
38
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
39
+
40
+/* Qwerty
41
+ * ,-----------------------------------------------------------------------------------.
42
+ * | Tab  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  | Bksp |
43
+ * |------+------+------+------+------+-------------+------+------+------+------+------|
44
+ * | Ctrl*|   A* |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   ;* |  "   |
45
+ * |------+------+------+------+------+------|------+------+------+------+------+------|
46
+ * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   /  |Enter |
47
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
48
+ * | Mouse|      | Alt  | GUI  |Lower*|    Space    |Raise*| GUI  | Alt  |      | Vim  |
49
+ * `-----------------------------------------------------------------------------------'
50
+ *
51
+ * - Ctrl acts as Esc when tapped.
52
+ * - Holding A or ; switches to movement layer.
53
+ * - Raise and Lower are one-shot layers.
54
+ */
55
+[_QWERTY] = {
56
+  {KC_TAB,  KC_Q,           KC_W,    KC_E,    KC_R,          KC_T,    KC_Y,    KC_U,          KC_I,    KC_O,    KC_P,              KC_BSPC},
57
+  {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},
58
+  {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) },
59
+  {TG(_MOUSE), X_____X,  KC_LALT, KC_LGUI, OSL(_LOWER),   KC_SPC,  KC_SPC,  OSL(_RAISE),   KC_LGUI, KC_LALT, X_____X, VIM_START }
60
+},
61
+
62
+/* Lower
63
+ * ,-----------------------------------------------------------------------------------.
64
+ * |  ~   |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   _  |   +  |   {  |   }  | Bksp |
65
+ * |------+------+------+------+------+-------------+------+------+------+------+------|
66
+ * |  Del |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  |  |   |
67
+ * |------+------+------+------+------+------|------+------+------+------+------+------|
68
+ * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |      |      | Home | End  |      |
69
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
70
+ * |      |      |      |      |      |             |      | Next | Vol- | Vol+ | Play |
71
+ * `-----------------------------------------------------------------------------------'
72
+ */
73
+[_LOWER] = {
74
+  {KC_TILD,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS,    KC_PLUS,    KC_LCBR, KC_RCBR, KC_BSPC},
75
+  {KC_DEL, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR,    KC_ASTR,    KC_LPRN, KC_RPRN, KC_PIPE},
76
+  {_______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  _______, _______, KC_HOME, KC_END,  _______},
77
+  {_______, TO(_QWERTY), _______, _______, _______, _______, _______, OSL(_ADJUST),    KC_MNXT,    KC_VOLD, KC_VOLU, KC_MPLY}
78
+},
79
+
80
+/* Raise
81
+ * ,-----------------------------------------------------------------------------------.
82
+ * |   `  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   -  |   =  |   [  |   ]  | Bksp |
83
+ * |------+------+------+------+------+-------------+------+------+------+------+------|
84
+ * |  Del |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |  \   |
85
+ * |------+------+------+------+------+------|------+------+------+------+------+------|
86
+ * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO # |ISO / |Pg Up |Pg Dn |      |
87
+ * |------+------+------+------+------+------+------+------+------+------+------+------|
88
+ * |      |      |      |      |      |             |      | Next | Vol- | Vol+ | Play |
89
+ * `-----------------------------------------------------------------------------------'
90
+ */
91
+[_RAISE] = {
92
+  {KC_GRV,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSPC},
93
+  {KC_DEL,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_BSLS},
94
+  {_______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  _______, _______, KC_PGUP, KC_PGDN, _______},
95
+  {_______, TO(_QWERTY), _______, _______, OSL(_ADJUST), _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
96
+},
97
+
98
+
99
+/* Adjust (Lower + Raise)
100
+ * ,-------------------------------------------------------------------------------------.
101
+ * |RGBPlain| Reset|      |      |      |      |      |      |      |      |      |  Del |
102
+ * |--------+------+------+------+------+-------------+------+------+------+------+------|
103
+ * |RGBMode-|      |      |Aud on|Audoff|AGnorm|AGswap|      |      |      |      |Lite+ |
104
+ * |--------+------+------+------+------+------|------+------+------+------+------+------|
105
+ * |RGBMode+|Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof|      |      |      |      |Lite- |
106
+ * |--------+------+------+------+------+------+------+------+------+------+------+------|
107
+ * |  RGB   |      |      |      |      |             |      |      |      |      |      |
108
+ * `-------------------------------------------------------------------------------------'
109
+ */
110
+[_ADJUST] = {
111
+  {RGB_MODE_PLAIN, RESET,   DEBUG,   _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL },
112
+  {RGB_MODE_REVERSE, _______, MU_MOD,  AU_ON,   AU_OFF,  AG_NORM, AG_SWAP, _______, _______, _______, _______, RGB_VAI},
113
+  {RGB_MODE_FORWARD, MUV_DE,  MUV_IN,  MU_ON,   MU_OFF,  MI_ON,   MI_OFF,  _______, _______, _______, _______, RGB_VAD},
114
+  {RGB_TOG, TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
115
+},
116
+
117
+
118
+/* movement layer (hold semicolon)
119
+ */
120
+[_MOVE] = {
121
+  {TO(_QWERTY), X_____X, X_____X, X_____X, X_____X, X_____X, KC_HOME, KC_PGDN, KC_PGUP, KC_END, X_____X, X_____X},
122
+  {_______,     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},
123
+  {_______,     X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, _______},
124
+  {X_____X,     TO(_QWERTY), _______, _______, _______, X_____X, X_____X, _______, _______, _______, TO(_QWERTY), _______}
125
+},
126
+
127
+/* mouse layer
128
+ */
129
+[_MOUSE] = {
130
+  {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  },
131
+  {_______,     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},
132
+  {_______,     X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, _______},
133
+  {_______,     TO(_QWERTY), _______, _______, _______, X_____X, X_____X, _______, _______, _______, TO(_QWERTY), _______}
134
+},
135
+
136
+/* vim edit mode. just has an escape -> _CMD key */
137
+[_EDIT] = {
138
+  {_______,     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
139
+  {VIM_START,   _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
140
+  {_______,     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
141
+  {_______,     TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, TO(_QWERTY), _______}
142
+},
143
+
144
+/* vim command layer.
145
+ */
146
+[_CMD] = {
147
+  {X_____X, X_____X, VIM_W, VIM_E, X_____X, X_____X, VIM_Y, VIM_U, VIM_I, VIM_O, VIM_P, X_____X},
148
+  {VIM_ESC,    VIM_A, VIM_S, VIM_D, X_____X, VIM_G, VIM_H, VIM_J, VIM_K, VIM_L, X_____X, X_____X},
149
+  {VIM_SHIFT,     X_____X, VIM_X, VIM_C, VIM_V, VIM_B, X_____X, X_____X, VIM_COMMA, VIM_PERIOD, X_____X, VIM_SHIFT},
150
+  {X_____X,     TO(_QWERTY), _______, _______, X_____X, X_____X, X_____X, X_____X, _______, _______, TO(_QWERTY), X_____X}
151
+}
152
+
153
+};
154
+
155
+bool process_record_user(uint16_t keycode, keyrecord_t *record) {
156
+  if(process_record_xtonhasvim(keycode, record)) {
157
+    // do nothing so far
158
+    return true;
159
+  } else {
160
+    // already handled by vim
161
+    return false;
162
+  }
163
+}
164
+
165
+/** Set just 4 LEDs closest to the user. Slightly less annoying to bystanders.*/
166
+void rgbflag(uint8_t r, uint8_t g, uint8_t b) {
167
+  for(int i = 0; i < RGBLED_NUM; i++){
168
+    switch(i) {
169
+      case 9 ... 12:
170
+        // rgblight_setrgb_at(r,g,b,i);
171
+        led[i].r = r;
172
+        led[i].g = g;
173
+        led[i].b = b;
174
+        break;
175
+      default:
176
+        // rgblight_setrgb_at(0,0,0,i);
177
+        led[i].r = 0;
178
+        led[i].g = 0;
179
+        led[i].b = 0;
180
+        break;
181
+    }
182
+  }
183
+  rgblight_set();
184
+}
185
+
186
+uint32_t layer_state_set_user(uint32_t state) {
187
+  if(rgblight_get_mode() == 1) {
188
+    switch (biton32(state)) {
189
+    case _RAISE:
190
+    case _LOWER:
191
+    case _ADJUST:
192
+        rgbflag(0x00,  0x00, 0xFF);
193
+        break;
194
+    case _MOVE:
195
+    case _MOUSE:
196
+        rgbflag(0xFF,  0x00, 0x00);
197
+        break;
198
+    case _CMD:
199
+        rgbflag(0x00,  0xFF, 0x00);
200
+        break;
201
+    case _EDIT:
202
+        rgbflag(0x7A,  0x00, 0xFF);
203
+        break;
204
+    default: //  for any other layers, or the default layer
205
+        rgbflag(0x00,  0xFF, 0xFF);
206
+        break;
207
+    }
208
+  }
209
+  return state;
210
+}

+ 9
- 0
keyboards/niu_mini/keymaps/xtonhasvim/readme.md View File

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

+ 6
- 0
keyboards/niu_mini/keymaps/xtonhasvim/rules.mk View File

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

+ 10
- 0
users/xtonhasvim/readme.md View File

@@ -0,0 +1,10 @@
1
+
2
+# Xton has Vim!
3
+
4
+Contains common code for Xton's vim emulation (vimulation?) layer.
5
+
6
+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.
7
+
8
+Works via OSX text editing shortcuts, mainly MOD+arrow combinations. This has some limitations and only works on OSX. 
9
+
10
+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.

+ 1
- 0
users/xtonhasvim/rules.mk View File

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

+ 599
- 0
users/xtonhasvim/xtonhasvim.c View File

@@ -0,0 +1,599 @@
1
+ /* Copyright 2015-2017 Christon DeWan
2
+ *
3
+ * This program is free software: you can redistribute it and/or modify
4
+ * it under the terms of the GNU General Public License as published by
5
+ * the Free Software Foundation, either version 2 of the License, or
6
+ * (at your option) any later version.
7
+ *
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+ * GNU General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
+ */
16
+
17
+#include "xtonhasvim.h"
18
+
19
+/************************************
20
+ * helper foo
21
+ ************************************/
22
+
23
+#define PRESS(kc) register_code(kc)
24
+#define RELEASE(kc) unregister_code(kc)
25
+
26
+static void TAP(uint16_t keycode) {
27
+    PRESS(keycode);
28
+    RELEASE(keycode);
29
+}
30
+
31
+static void CMD(uint16_t keycode) {
32
+  PRESS(KC_LGUI);
33
+    TAP(keycode);
34
+  RELEASE(KC_LGUI);
35
+}
36
+
37
+static void CTRL(uint16_t keycode) {
38
+  PRESS(KC_LCTRL);
39
+    TAP(keycode);
40
+  RELEASE(KC_LCTRL);
41
+}
42
+
43
+static void SHIFT(uint16_t keycode) {
44
+  PRESS(KC_LSHIFT);
45
+    TAP(keycode);
46
+  RELEASE(KC_LSHIFT);
47
+}
48
+
49
+static void ALT(uint16_t keycode) {
50
+  PRESS(KC_LALT);
51
+    TAP(keycode);
52
+  RELEASE(KC_LALT);
53
+}
54
+
55
+
56
+uint16_t vstate = VIM_START;
57
+bool yank_was_lines = false;
58
+bool SHIFTED = false;
59
+uint32_t mod_override_layer_state = 0;
60
+uint16_t mod_override_triggering_key = 0;
61
+bool do_check_kb_clear = false;
62
+
63
+void vim_reset(void) {
64
+  vstate = VIM_START;
65
+  SHIFTED = false;
66
+  yank_was_lines = false;
67
+}
68
+
69
+void edit(void) { vstate = VIM_START; layer_on(_EDIT); layer_off(_CMD); }
70
+#define EDIT edit()
71
+
72
+
73
+void simple_movement(uint16_t keycode) {
74
+  switch(keycode) {
75
+    case VIM_B:
76
+      PRESS(KC_LALT);
77
+        SHIFT(KC_LEFT); // select to start of this word
78
+      RELEASE(KC_LALT);
79
+      break;
80
+    case VIM_E:
81
+      PRESS(KC_LALT);
82
+        SHIFT(KC_RIGHT); // select to end of this word
83
+      RELEASE(KC_LALT);
84
+      break;
85
+    case VIM_H:
86
+      SHIFT(KC_LEFT);
87
+      break;
88
+    case VIM_J:
89
+      CMD(KC_LEFT);
90
+      SHIFT(KC_DOWN);
91
+      SHIFT(KC_DOWN);
92
+      break;
93
+    case VIM_K:
94
+      CMD(KC_LEFT);
95
+      TAP(KC_DOWN);
96
+      SHIFT(KC_UP);
97
+      SHIFT(KC_UP);
98
+      break;
99
+    case VIM_L:
100
+      SHIFT(KC_RIGHT);
101
+      break;
102
+    case VIM_W:
103
+      PRESS(KC_LALT);
104
+      SHIFT(KC_RIGHT); // select to end of this word
105
+      SHIFT(KC_RIGHT); // select to end of next word
106
+      SHIFT(KC_LEFT);  // select to start of next word
107
+      RELEASE(KC_LALT);
108
+      break;
109
+  }
110
+}
111
+
112
+bool process_record_xtonhasvim(uint16_t keycode, keyrecord_t *record) {
113
+  if(record->event.pressed && layer_state_is(_CMD) && IS_MOD(keycode)) {
114
+    mod_override_layer_state = layer_state;
115
+    mod_override_triggering_key = keycode;
116
+    layer_clear();
117
+    return true; // let the event fall through...
118
+  }
119
+  if(mod_override_layer_state && !record->event.pressed && keycode == mod_override_triggering_key) {
120
+    layer_state_set(mod_override_layer_state);
121
+    mod_override_layer_state = 0;
122
+    mod_override_triggering_key = 0;
123
+    return true;
124
+  }
125
+
126
+  if (VIM_START <= keycode && keycode <= VIM_ESC) {
127
+    if(keycode == VIM_SHIFT) {
128
+      SHIFTED = record->event.pressed;
129
+      return false;
130
+    }
131
+
132
+    if (record->event.pressed) {
133
+      if(keycode == VIM_START) {
134
+        // entry from anywhere
135
+        layer_on(_CMD);
136
+        vstate = VIM_START;
137
+        return false;
138
+      }
139
+      switch(vstate) {
140
+        case VIM_START:
141
+          switch(keycode){
142
+            /*****************************
143
+             * ground state
144
+             *****************************/
145
+            case VIM_A:
146
+              if(SHIFTED) {
147
+                // CMD(KC_RIGHT);
148
+                CTRL(KC_E);
149
+              } else {
150
+                TAP(KC_RIGHT);
151
+              }
152
+              EDIT;
153
+              break;
154
+            case VIM_B:
155
+              PRESS(KC_LALT);
156
+              PRESS(KC_LEFT);
157
+              break;
158
+            case VIM_C:
159
+              if(SHIFTED) {
160
+                PRESS(KC_LSHIFT);
161
+                  CMD(KC_RIGHT);
162
+                RELEASE(KC_LSHIFT);
163
+                CMD(KC_X);
164
+                yank_was_lines = false;
165
+                EDIT;
166
+              } else {
167
+                vstate = VIM_C;
168
+              }
169
+              break;
170
+            case VIM_D:
171
+              if(SHIFTED) {
172
+                TAP(KC_K);
173
+              } else {
174
+                vstate = VIM_D;
175
+              }
176
+              break;
177
+            case VIM_E:
178
+              PRESS(KC_LALT);
179
+              PRESS(KC_RIGHT);
180
+              break;
181
+            case VIM_G:
182
+              if(SHIFTED) {
183
+                TAP(KC_END);
184
+              } else {
185
+                vstate = VIM_G;
186
+              }
187
+              break;
188
+            case VIM_H:
189
+              PRESS(KC_LEFT);
190
+              break;
191
+            case VIM_I:
192
+              if(SHIFTED){
193
+                CTRL(KC_A);
194
+              }
195
+              EDIT;
196
+              break;
197
+            case VIM_J:
198
+              if(SHIFTED) {
199
+                CMD(KC_RIGHT);
200
+                TAP(KC_DEL);
201
+              } else {
202
+                PRESS(KC_DOWN);
203
+              }
204
+              break;
205
+            case VIM_K:
206
+              PRESS(KC_UP);
207
+              break;
208
+            case VIM_L:
209
+              PRESS(KC_RIGHT);
210
+              break;
211
+            case VIM_O:
212
+              if(SHIFTED) {
213
+                CMD(KC_LEFT);
214
+                TAP(KC_ENTER);
215
+                TAP(KC_UP);
216
+                EDIT;
217
+              } else {
218
+                CMD(KC_RIGHT);
219
+                TAP(KC_ENTER);
220
+                EDIT;
221
+              }
222
+              break;
223
+            case VIM_P:
224
+              if(SHIFTED) {
225
+                CMD(KC_LEFT);
226
+                CMD(KC_V);
227
+              } else {
228
+                if(yank_was_lines) {
229
+                  CMD(KC_RIGHT);
230
+                  TAP(KC_RIGHT);
231
+                  CMD(KC_V);
232
+                } else {
233
+                  CMD(KC_V);
234
+                }
235
+              }
236
+              break;
237
+            case VIM_S:
238
+              // s for substitute?
239
+              if(SHIFTED) {
240
+                CMD(KC_LEFT);
241
+                PRESS(KC_LSHIFT);
242
+                  CMD(KC_RIGHT);
243
+                RELEASE(KC_LSHIFT);
244
+                CMD(KC_X);
245
+                yank_was_lines = false;
246
+                EDIT;
247
+              } else {
248
+                SHIFT(KC_RIGHT);
249
+                CMD(KC_X);
250
+                yank_was_lines = false;
251
+                EDIT;
252
+              }
253
+              break;
254
+            case VIM_U:
255
+              if(SHIFTED) {
256
+                PRESS(KC_LSFT);
257
+                  CMD(KC_Z);
258
+                RELEASE(KC_LSHIFT);
259
+              } else {
260
+                CMD(KC_Z);
261
+              }
262
+              break;
263
+            case VIM_V:
264
+              if(SHIFTED) {
265
+                CMD(KC_LEFT);
266
+                SHIFT(KC_DOWN);
267
+                vstate = VIM_VS;
268
+              } else {
269
+                vstate = VIM_V;
270
+              }
271
+              break;
272
+            case VIM_W:
273
+              PRESS(KC_LALT);
274
+                TAP(KC_RIGHT);
275
+                TAP(KC_RIGHT);
276
+                TAP(KC_LEFT);
277
+              RELEASE(KC_LALT);
278
+              break;
279
+            case VIM_X:
280
+              // SHIFT(KC_RIGHT);
281
+              // CMD(KC_X);
282
+              PRESS(KC_DEL);
283
+              break;
284
+            case VIM_Y:
285
+              if(SHIFTED) {
286
+                CMD(KC_LEFT);
287
+                SHIFT(KC_DOWN);
288
+                CMD(KC_C);
289
+                TAP(KC_RIGHT);
290
+                yank_was_lines = true;
291
+              } else {
292
+                vstate = VIM_Y;
293
+              }
294
+              break;
295
+            case VIM_COMMA:
296
+              if(SHIFTED) {
297
+                // indent
298
+                CMD(KC_LBRACKET);
299
+              } else {
300
+                // toggle comment
301
+                CMD(KC_SLASH);
302
+              }
303
+              break;
304
+            case VIM_PERIOD:
305
+              if(SHIFTED) {
306
+                // outdent
307
+                CMD(KC_RBRACKET);
308
+              }
309
+              break;
310
+          }
311
+          break;
312
+        case VIM_C:
313
+          /*****************************
314
+           * c-  ...for change. I never use this...
315
+           *****************************/
316
+          switch(keycode) {
317
+          case VIM_B:
318
+          case VIM_E:
319
+          case VIM_H:
320
+          case VIM_J:
321
+          case VIM_K:
322
+          case VIM_L:
323
+          case VIM_W:
324
+            simple_movement(keycode);
325
+            CMD(KC_X);
326
+            yank_was_lines = false;
327
+            EDIT;
328
+            break;
329
+
330
+          case VIM_C:
331
+            CMD(KC_LEFT);
332
+            PRESS(KC_LSHIFT);
333
+              CMD(KC_RIGHT);
334
+            RELEASE(KC_LSHIFT);
335
+            CMD(KC_X);
336
+            yank_was_lines = false;
337
+            EDIT;
338
+            break;
339
+          case VIM_I:
340
+            vstate = VIM_CI;
341
+            break;
342
+          default:
343
+            vstate = VIM_START;
344
+            break;
345
+          }
346
+          break;
347
+        case VIM_CI:
348
+          /*****************************
349
+           * ci-  ...change inner word
350
+           *****************************/
351
+          switch(keycode) {
352
+            case VIM_W:
353
+              ALT(KC_LEFT);
354
+              PRESS(KC_LSHIFT);
355
+                ALT(KC_RIGHT);
356
+              RELEASE(KC_LSHIFT);
357
+              CMD(KC_X);
358
+              yank_was_lines = false;
359
+              EDIT;
360
+            default:
361
+              vstate = VIM_START;
362
+              break;
363
+          }
364
+          break;
365
+        case VIM_D:
366
+          /*****************************
367
+           * d-  ...delete stuff
368
+           *****************************/
369
+          switch(keycode) {
370
+          case VIM_B:
371
+          case VIM_E:
372
+          case VIM_H:
373
+          case VIM_J:
374
+          case VIM_K:
375
+          case VIM_L:
376
+          case VIM_W:
377
+            simple_movement(keycode);
378
+            CMD(KC_X);
379
+            yank_was_lines = false;
380
+            break;
381
+          case VIM_D:
382
+            CMD(KC_LEFT);
383
+            SHIFT(KC_DOWN);
384
+            CMD(KC_X);
385
+            yank_was_lines = true;
386
+            vstate = VIM_START;
387
+            break;
388
+          case VIM_I:
389
+            vstate = VIM_DI;
390
+            break;
391
+          default:
392
+            vstate = VIM_START;
393
+            break;
394
+          }
395
+          break;
396
+        case VIM_DI:
397
+          /*****************************
398
+           * ci-  ...delete a word... FROM THE INSIDE!
399
+           *****************************/
400
+          switch(keycode) {
401
+            case VIM_W:
402
+              ALT(KC_LEFT);
403
+              PRESS(KC_LSHIFT);
404
+                ALT(KC_RIGHT);
405
+              RELEASE(KC_LSHIFT);
406
+              CMD(KC_X);
407
+              yank_was_lines = false;
408
+              vstate = VIM_START;
409
+            default:
410
+              vstate = VIM_START;
411
+              break;
412
+          }
413
+          break;
414
+        case VIM_V:
415
+          /*****************************
416
+           * visual!
417
+           *****************************/
418
+          switch(keycode) {
419
+            case VIM_D:
420
+            case VIM_X:
421
+              CMD(KC_X);
422
+              yank_was_lines = false;
423
+              vstate = VIM_START;
424
+              break;
425
+            case VIM_B:
426
+              PRESS(KC_LALT);
427
+              PRESS(KC_LSHIFT);
428
+              PRESS(KC_LEFT);
429
+              // leave open for key repeat
430
+              break;
431
+            case VIM_E:
432
+              PRESS(KC_LALT);
433
+              PRESS(KC_LSHIFT);
434
+              PRESS(KC_RIGHT);
435
+              // leave open for key repeat
436
+              break;
437
+            case VIM_H:
438
+              PRESS(KC_LSHIFT);
439
+              PRESS(KC_LEFT);
440
+              break;
441
+            case VIM_I:
442
+              vstate = VIM_VI;
443
+              break;
444
+            case VIM_J:
445
+              PRESS(KC_LSHIFT);
446
+              PRESS(KC_DOWN);
447
+              break;
448
+            case VIM_K:
449
+              PRESS(KC_LSHIFT);
450
+              PRESS(KC_UP);
451
+              break;
452
+            case VIM_L:
453
+              PRESS(KC_LSHIFT);
454
+              PRESS(KC_RIGHT);
455
+              break;
456
+            case VIM_W:
457
+              PRESS(KC_LALT);
458
+              SHIFT(KC_RIGHT); // select to end of this word
459
+              SHIFT(KC_RIGHT); // select to end of next word
460
+              SHIFT(KC_LEFT);  // select to start of next word
461
+              RELEASE(KC_LALT);
462
+              break;
463
+            case VIM_Y:
464
+              CMD(KC_C);
465
+              TAP(KC_RIGHT);
466
+              yank_was_lines = false;
467
+              vstate = VIM_START;
468
+              break;
469
+            case VIM_V:
470
+            case VIM_ESC:
471
+              TAP(KC_RIGHT);
472
+              vstate = VIM_START;
473
+              break;
474
+            default:
475
+              // do nothing
476
+              break;
477
+          }
478
+          break;
479
+        case VIM_VI:
480
+          /*****************************
481
+           * vi-  ...select a word... FROM THE INSIDE!
482
+           *****************************/
483
+          switch(keycode) {
484
+            case VIM_W:
485
+              ALT(KC_LEFT);
486
+              PRESS(KC_LSHIFT);
487
+                ALT(KC_RIGHT);
488
+              RELEASE(KC_LSHIFT);
489
+              vstate = VIM_V;
490
+            default:
491
+              // ignore
492
+              vstate = VIM_V;
493
+              break;
494
+          }
495
+          break;
496
+        case VIM_VS:
497
+          /*****************************
498
+           * visual line
499
+           *****************************/
500
+          switch(keycode) {
501
+            case VIM_D:
502
+            case VIM_X:
503
+              CMD(KC_X);
504
+              yank_was_lines = true;
505
+              vstate = VIM_START;
506
+              break;
507
+            case VIM_J:
508
+              PRESS(KC_LSHIFT);
509
+              PRESS(KC_DOWN);
510
+              break;
511
+            case VIM_K:
512
+              PRESS(KC_LSHIFT);
513
+              PRESS(KC_UP);
514
+              break;
515
+            case VIM_Y:
516
+              CMD(KC_C);
517
+              yank_was_lines = true;
518
+              TAP(KC_RIGHT);
519
+              vstate = VIM_START;
520
+              break;
521
+            case VIM_V:
522
+            case VIM_ESC:
523
+              TAP(KC_RIGHT);
524
+              vstate = VIM_START;
525
+              break;
526
+            default:
527
+              // do nothing
528
+              break;
529
+          }
530
+          break;
531
+        case VIM_G:
532
+          /*****************************
533
+           * gg, and a grab-bag of other macros i find useful
534
+           *****************************/
535
+          switch(keycode) {
536
+            case VIM_G:
537
+              TAP(KC_HOME);
538
+              break;
539
+            // codes b
540
+            case VIM_H:
541
+              CTRL(KC_A);
542
+              break;
543
+            case VIM_J:
544
+              PRESS(KC_PGDN);
545
+              break;
546
+            case VIM_K:
547
+              PRESS(KC_PGUP);
548
+              break;
549
+            case VIM_L:
550
+              CTRL(KC_E);
551
+              break;
552
+            default:
553
+              // do nothing
554
+              break;
555
+          }
556
+          vstate = VIM_START;
557
+          break;
558
+        case VIM_Y:
559
+          /*****************************
560
+           * yoink!
561
+           *****************************/
562
+          switch(keycode) {
563
+          case VIM_B:
564
+          case VIM_E:
565
+          case VIM_H:
566
+          case VIM_J:
567
+          case VIM_K:
568
+          case VIM_L:
569
+          case VIM_W:
570
+            simple_movement(keycode);
571
+            CMD(KC_C);
572
+            TAP(KC_RIGHT);
573
+            yank_was_lines = false;
574
+            break;
575
+          case VIM_Y:
576
+            CMD(KC_LEFT);
577
+            SHIFT(KC_DOWN);
578
+            CMD(KC_C);
579
+            TAP(KC_RIGHT);
580
+            yank_was_lines = true;
581
+            break;
582
+          default:
583
+            // NOTHING
584
+            break;
585
+          }
586
+          vstate = VIM_START;
587
+          break;
588
+        }
589
+    } else {
590
+      /************************
591
+       * key release events
592
+       ************************/
593
+      clear_keyboard();
594
+    }
595
+    return false;
596
+  } else {
597
+    return true;
598
+  }
599
+}

+ 66
- 0
users/xtonhasvim/xtonhasvim.h View File

@@ -0,0 +1,66 @@
1
+ /* Copyright 2015-2017 Christon DeWan
2
+ *
3
+ * This program is free software: you can redistribute it and/or modify
4
+ * it under the terms of the GNU General Public License as published by
5
+ * the Free Software Foundation, either version 2 of the License, or
6
+ * (at your option) any later version.
7
+ *
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+ * GNU General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
+ */
16
+
17
+#ifndef USERSPACE
18
+#define USERSPACE
19
+
20
+#include QMK_KEYBOARD_H
21
+#include "action_layer.h"
22
+
23
+#define X_____X KC_NO
24
+
25
+bool process_record_xtonhasvim(uint16_t keycode, keyrecord_t *record);
26
+
27
+enum xtonhasvim_keycodes {
28
+  DUMMY = SAFE_RANGE,
29
+  VIM_START, // bookend for vim states
30
+  VIM_A,
31
+  VIM_B,
32
+  VIM_C,
33
+  VIM_CI,
34
+  VIM_D,
35
+  VIM_DI,
36
+  VIM_E,
37
+  VIM_H,
38
+  VIM_G,
39
+  VIM_I,
40
+  VIM_J,
41
+  VIM_K,
42
+  VIM_L,
43
+  VIM_O,
44
+  VIM_P,
45
+  VIM_S,
46
+  VIM_U,
47
+  VIM_V,
48
+  VIM_VS, // visual-line
49
+  VIM_VI,
50
+  VIM_W,
51
+  VIM_X,
52
+  VIM_Y,
53
+  VIM_PERIOD, // to support indent/outdent
54
+  VIM_COMMA,  // and toggle comments
55
+  VIM_SHIFT, // avoid side-effect of supporting real shift.
56
+  VIM_ESC, // bookend
57
+  VIM_SAFE_RANGE // start other keycodes here.
58
+};
59
+
60
+enum xtonhasvim_layers {
61
+  _EDIT = 12,
62
+  _CMD
63
+};
64
+
65
+
66
+#endif

Loading…
Cancel
Save