1 /* Copyright 2015-2017 Christon DeWan
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.
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.
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/>.
17 #include "xtonhasvim.h"
19 /************************************
21 ************************************/
23 #define PRESS(kc) register_code(kc)
24 #define RELEASE(kc) unregister_code(kc)
26 static void TAP(uint16_t keycode) {
31 static void CMD(uint16_t keycode) {
37 static void CTRL(uint16_t keycode) {
43 static void SHIFT(uint16_t keycode) {
49 static void ALT(uint16_t keycode) {
56 uint16_t vstate = VIM_START;
57 bool yank_was_lines = false;
59 uint32_t mod_override_layer_state = 0;
60 uint16_t mod_override_triggering_key = 0;
61 bool do_check_kb_clear = false;
63 void vim_reset(void) {
66 yank_was_lines = false;
69 void edit(void) { vstate = VIM_START; layer_on(_EDIT); layer_off(_CMD); }
73 void simple_movement(uint16_t keycode) {
77 SHIFT(KC_LEFT); // select to start of this word
82 SHIFT(KC_RIGHT); // select to end of this word
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
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;
117 return true; // let the event fall through...
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;
126 if (VIM_START <= keycode && keycode <= VIM_ESC) {
127 if(keycode == VIM_SHIFT) {
128 SHIFTED = record->event.pressed;
132 if (record->event.pressed) {
133 if(keycode == VIM_START) {
134 // entry from anywhere
142 /*****************************
144 *****************************/
164 yank_was_lines = false;
245 yank_was_lines = false;
250 yank_was_lines = false;
290 yank_was_lines = true;
313 /*****************************
314 * c- ...for change. I never use this...
315 *****************************/
324 simple_movement(keycode);
326 yank_was_lines = false;
336 yank_was_lines = false;
348 /*****************************
349 * ci- ...change inner word
350 *****************************/
358 yank_was_lines = false;
366 /*****************************
368 *****************************/
377 simple_movement(keycode);
379 yank_was_lines = false;
385 yank_was_lines = true;
397 /*****************************
398 * ci- ...delete a word... FROM THE INSIDE!
399 *****************************/
407 yank_was_lines = false;
415 /*****************************
417 *****************************/
422 yank_was_lines = false;
429 // leave open for key repeat
435 // leave open for key repeat
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
466 yank_was_lines = false;
480 /*****************************
481 * vi- ...select a word... FROM THE INSIDE!
482 *****************************/
497 /*****************************
499 *****************************/
504 yank_was_lines = true;
517 yank_was_lines = true;
532 /*****************************
533 * gg, and a grab-bag of other macros i find useful
534 *****************************/
559 /*****************************
561 *****************************/
570 simple_movement(keycode);
573 yank_was_lines = false;
580 yank_was_lines = true;
590 /************************
592 ************************/