vim.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. #include "config.h"
  2. #include "print.h"
  3. #include "keycode.h"
  4. #include "quantum.h"
  5. #include "quantum_keycodes.h"
  6. #define NOR_MOD TO(NORMAL_MODE)
  7. #define INS_MOD TO(INSERT_MODE)
  8. #define PRESS(keycode) register_code16(keycode)
  9. #define RELEASE(keycode) unregister_code16(keycode)
  10. uint16_t VIM_QUEUE = KC_NO;
  11. enum custom_keycodes {
  12. PLACEHOLDER = SAFE_RANGE, // can always be here
  13. VIM_A,
  14. VIM_B,
  15. VIM_C,
  16. VIM_CI,
  17. VIM_D,
  18. VIM_DI,
  19. VIM_E,
  20. VIM_H,
  21. VIM_I,
  22. VIM_J,
  23. VIM_K,
  24. VIM_L,
  25. VIM_O,
  26. VIM_P,
  27. VIM_S,
  28. VIM_U,
  29. VIM_V,
  30. VIM_VI,
  31. VIM_W,
  32. VIM_X,
  33. VIM_Y,
  34. EPRM,
  35. VRSN,
  36. RGB_SLD,
  37. };
  38. void VIM_APPEND(void);
  39. void VIM_APPEND_LINE(void);
  40. void VIM_BACK(void);
  41. void VIM_CHANGE_BACK(void);
  42. void VIM_CHANGE_DOWN(void);
  43. void VIM_CHANGE_END(void);
  44. void VIM_CHANGE_INNER_WORD(void);
  45. void VIM_CHANGE_LEFT(void);
  46. void VIM_CHANGE_LINE(void);
  47. void VIM_CHANGE_RIGHT(void);
  48. void VIM_CHANGE_UP(void);
  49. void VIM_CHANGE_WHOLE_LINE(void);
  50. void VIM_CHANGE_WORD(void);
  51. void VIM_CUT(void);
  52. void VIM_DELETE_BACK(void);
  53. void VIM_DELETE_DOWN(void);
  54. void VIM_DELETE_END(void);
  55. void VIM_DELETE_INNER_WORD(void);
  56. void VIM_DELETE_LEFT(void);
  57. void VIM_DELETE_LINE(void);
  58. void VIM_DELETE_RIGHT(void);
  59. void VIM_DELETE_UP(void);
  60. void VIM_DELETE_WHOLE_LINE(void);
  61. void VIM_DELETE_WORD(void);
  62. void VIM_END(void);
  63. void VIM_JOIN(void);
  64. void VIM_OPEN(void);
  65. void VIM_OPEN_ABOVE(void);
  66. void VIM_PUT(void);
  67. void VIM_SUBSTITUTE(void);
  68. void VIM_UNDO(void);
  69. void VIM_VISUAL_BACK(void);
  70. void VIM_VISUAL_DOWN(void);
  71. void VIM_VISUAL_END(void);
  72. void VIM_VISUAL_INNER_WORD(void);
  73. void VIM_VISUAL_LEFT(void);
  74. void VIM_VISUAL_RIGHT(void);
  75. void VIM_VISUAL_UP(void);
  76. void VIM_VISUAL_WORD(void);
  77. void VIM_WORD(void);
  78. void VIM_YANK(void);
  79. void TAP(uint16_t keycode) {
  80. PRESS(keycode);
  81. RELEASE(keycode);
  82. }
  83. void CMD(uint16_t keycode) {
  84. PRESS(KC_LGUI);
  85. TAP(keycode);
  86. RELEASE(KC_LGUI);
  87. }
  88. void CTRL(uint16_t keycode) {
  89. PRESS(KC_LCTL);
  90. TAP(keycode);
  91. RELEASE(KC_LCTL);
  92. }
  93. void SHIFT(uint16_t keycode) {
  94. PRESS(KC_LSFT);
  95. TAP(keycode);
  96. RELEASE(KC_LSFT);
  97. }
  98. void ALT(uint16_t keycode) {
  99. PRESS(KC_LALT);
  100. TAP(keycode);
  101. RELEASE(KC_LALT);
  102. }
  103. /**
  104. * Sets the `VIM_QUEUE` variable to the incoming keycode.
  105. * Pass `KC_NO` to cancel the operation.
  106. * @param keycode
  107. */
  108. void VIM_LEADER(uint16_t keycode) {
  109. VIM_QUEUE = keycode;
  110. switch(keycode) {
  111. case VIM_C: print("\e[32mc\e[0m"); break;
  112. case VIM_CI: print("\e[32mi\e[0m"); break;
  113. case VIM_D: print("\e[32md\e[0m"); break;
  114. case VIM_DI: print("\e[32mi\e[0m"); break;
  115. case VIM_V: print("\e[32mv\e[0m"); break;
  116. case VIM_VI: print("\e[32mi\e[0m"); break;
  117. case KC_NO: print("❎"); break;
  118. }
  119. }
  120. /***
  121. * ####### # # ####### ##### # # ####### #######
  122. * # # ## # # # # # # # # #
  123. * # # # # # # # # # # # #
  124. * # # # # # ##### ##### ####### # # #
  125. * # # # # # # # # # # # #
  126. * # # # ## # # # # # # # #
  127. * ####### # # ####### ##### # # ####### #
  128. *
  129. */
  130. /**
  131. * Vim-like `append` command.
  132. * Works by sending →.
  133. */
  134. void VIM_APPEND(void) {
  135. print("\e[31ma\e[0m");
  136. TAP(KC_RIGHT);
  137. layer_on(INSERT_MODE);
  138. }
  139. /**
  140. * Vim-like `back` command
  141. * Simulates vim's `b` command by sending ⌥←
  142. */
  143. void VIM_BACK(void) {
  144. print("\e[31mb\e[0m");
  145. ALT(KC_LEFT);
  146. }
  147. /**
  148. * Vim-like `cut` command
  149. * Simulates vim's `x` command by sending ⇧→ then ⌘X.
  150. */
  151. void VIM_CUT(void) {
  152. print("\e[31mx\e[0m");
  153. SHIFT(KC_RIGHT);
  154. CMD(KC_X);
  155. }
  156. /**
  157. * Vim-like `down` command
  158. * Sends ↓
  159. */
  160. void VIM_DOWN(void) {
  161. print("\e[31mj\e[0m");
  162. TAP(KC_DOWN);
  163. }
  164. /**
  165. * Vim-like `end` command
  166. * Simulates vim's `e` command by sending ⌥→
  167. */
  168. void VIM_END(void) {
  169. print("\e[31me\e[0m");
  170. ALT(KC_RIGHT);
  171. }
  172. /**
  173. * Vim-like `left` command
  174. * Sends ←
  175. */
  176. void VIM_LEFT(void) {
  177. print("\e[31mh\e[0m");
  178. VIM_LEADER(KC_NO);
  179. TAP(KC_LEFT);
  180. }
  181. /**
  182. * Vim-like `open` command.
  183. * Works by sending ⌘→ to move to the end of the line, `enter` to open a new line,
  184. * then switching to insert mode.
  185. */
  186. void VIM_OPEN(void) {
  187. print("\e[31mo\e[0m");
  188. VIM_LEADER(KC_NO);
  189. CMD(KC_RIGHT);
  190. TAP(KC_ENTER);
  191. layer_on(INSERT_MODE);
  192. }
  193. /**
  194. * Vim-like `put` command
  195. * Simulates vim's `p` command by sending ⌘V
  196. */
  197. void VIM_PUT(void) {
  198. print("\e[31mp\e[0m");
  199. VIM_LEADER(KC_NO);
  200. CMD(KC_V);
  201. }
  202. /**
  203. * Vim-like `put before` command
  204. * Simulates vim's `P` command by sending ↑, ⌘←, then ⌘V
  205. */
  206. void VIM_PUT_BEFORE(void) {
  207. print("\e[31mP\e[0m");
  208. VIM_LEADER(KC_NO);
  209. TAP(KC_UP);
  210. CMD(KC_LEFT);
  211. CMD(KC_V);
  212. }
  213. /**
  214. * Vim-like `right` command
  215. * Sends →
  216. */
  217. void VIM_RIGHT(void) {
  218. print("\e[31ml\e[0m");
  219. VIM_LEADER(KC_NO);
  220. TAP(KC_RIGHT);
  221. }
  222. /**
  223. * Vim-like `substitute` command
  224. * Simulates vim's `s` command by sending ⇧→ to select the next character, then
  225. * ⌘X to cut it, then entering insert mode.
  226. */
  227. void VIM_SUBSTITUTE(void) {
  228. print("\e[31ms\e[0m");
  229. VIM_LEADER(KC_NO);
  230. SHIFT(KC_RIGHT);
  231. CMD(KC_X);
  232. layer_on(INSERT_MODE);
  233. }
  234. /**
  235. * Vim-like `undo` command
  236. * Simulates vim's `u` command by sending ⌘Z
  237. */
  238. void VIM_UNDO(void) {
  239. print("\e[31mu\e[0m");
  240. VIM_LEADER(KC_NO);
  241. CMD(KC_Z);
  242. }
  243. /**
  244. * Vim-like `up` command
  245. * Sends ↑
  246. */
  247. void VIM_UP(void) {
  248. print("\e[31mk\e[0m");
  249. VIM_LEADER(KC_NO);
  250. TAP(KC_UP);
  251. }
  252. /**
  253. * Vim-like `word` command
  254. * Simulates vim's `w` command by moving the cursor first to the
  255. * end of the current word, then to the end of the next word,
  256. * then to the beginning of that word.
  257. */
  258. void VIM_WORD(void) {
  259. print("\e[31mw\e[0m");
  260. VIM_LEADER(KC_NO);
  261. PRESS(KC_LALT);
  262. TAP(KC_RIGHT);
  263. TAP(KC_RIGHT);
  264. TAP(KC_LEFT);
  265. RELEASE(KC_LALT);
  266. }
  267. /**
  268. * Vim-like `yank` command
  269. * Simulates vim's `y` command by sending ⌘C
  270. */
  271. void VIM_YANK(void) {
  272. print("\e[31my\e[0m");
  273. VIM_LEADER(KC_NO);
  274. CMD(KC_C);
  275. }
  276. /**
  277. * Vim-like `yank line` command
  278. * Simulates vim's `y` command by sending ⌘← then ⇧⌘→ then ⌘C
  279. */
  280. void VIM_YANK_LINE(void) {
  281. print("\e[31mY\e[0m");
  282. VIM_LEADER(KC_NO);
  283. CMD(KC_LEFT);
  284. PRESS(KC_LSFT);
  285. CMD(KC_RIGHT);
  286. RELEASE(KC_LSFT);
  287. CMD(KC_C);
  288. }
  289. /***
  290. * ##### # # ### ####### ####### ####### ######
  291. * # # # # # # # # # #
  292. * # # # # # # # # #
  293. * ##### ####### # ##### # ##### # #
  294. * # # # # # # # # #
  295. * # # # # # # # # # #
  296. * ##### # # ### # # ####### ######
  297. *
  298. */
  299. /**
  300. * Vim-like `append to line` command
  301. * Simulates vim's `A` command by sending ⌘→ then switching to insert mode.
  302. */
  303. void VIM_APPEND_LINE(void) {
  304. print("\e[31mA\e[0m");
  305. VIM_LEADER(KC_NO);
  306. CMD(KC_RIGHT);
  307. layer_on(INSERT_MODE);
  308. }
  309. /**
  310. * Vim-like `change line` command
  311. * Simulates vim's `C` command by sending ⌃K then switching to insert mode.
  312. */
  313. void VIM_CHANGE_LINE(void) {
  314. print("\e[31mC\e[0m");
  315. VIM_LEADER(KC_NO);
  316. VIM_DELETE_LINE();
  317. layer_on(INSERT_MODE);
  318. }
  319. /**
  320. * Vim-like 'delete line' command
  321. * Simulates vim's `D` command by sending ⌃K to kill the line
  322. */
  323. void VIM_DELETE_LINE(void) {
  324. print("\e[31mD\e[0m");
  325. VIM_LEADER(KC_NO);
  326. CTRL(KC_K);
  327. }
  328. /**
  329. * Vim-like 'join lines' command
  330. * Simulates vim's `J` command by sending ⌘→ to go to the end of the line, then
  331. * DELETE to join the lines
  332. */
  333. void VIM_JOIN(void) {
  334. print("\e[31mJ\e[0m");
  335. VIM_LEADER(KC_NO);
  336. CMD(KC_RIGHT);
  337. TAP(KC_DELETE);
  338. VIM_LEADER(KC_NO);
  339. }
  340. /**
  341. * Vim-like 'open above' command
  342. * Simulates vim's `O` command by sending ⌘→ to go to the start of the line,
  343. * enter to move the line down, ↑ to move up to the new line, then switching to
  344. * insert mode.
  345. */
  346. void VIM_OPEN_ABOVE(void) {
  347. print("\e[31mO\e[0m");
  348. VIM_LEADER(KC_NO);
  349. CMD(KC_LEFT);
  350. TAP(KC_ENTER);
  351. TAP(KC_UP);
  352. layer_on(INSERT_MODE);
  353. }
  354. /**
  355. * Vim-like 'change whole line' command
  356. * Simulates vim's `S` `cc` or `c$` commands by sending ⌘← to go to the start of the line,
  357. * ⌃K to kill the line, then switching to insert mode.
  358. */
  359. void VIM_CHANGE_WHOLE_LINE(void) {
  360. print("\e[31mS\e[0m");
  361. VIM_LEADER(KC_NO);
  362. CMD(KC_LEFT);
  363. VIM_CHANGE_LINE();
  364. }
  365. /***
  366. * ###### ###### ###### ####### ####### ### # # ####### ######
  367. * # # # # # # # # # # # # # #
  368. * # # # # # # # # # # # # # #
  369. * # # ###### ###### ##### ##### # # ##### # #
  370. * # # # # # # # # # # # # #
  371. * # # # # # # # # # # # # #
  372. * ###### # # # ####### # ### # # ####### ######
  373. *
  374. */
  375. /**
  376. * Vim-like `delete to end` command
  377. * Simulates vim's `de` command by sending ⌥⇧→ then ⌘X.
  378. */
  379. void VIM_DELETE_END(void) {
  380. print("\e[31me\e[0m");
  381. VIM_LEADER(KC_NO);
  382. PRESS(KC_LALT);
  383. SHIFT(KC_RIGHT); // select to end of this word
  384. RELEASE(KC_LALT);
  385. CMD(KC_X);
  386. }
  387. /**
  388. * Vim-like `delete whole line` command
  389. * Simulates vim's `dd` command by sending ⌘← to move to start of line,
  390. * selecting the whole line, then sending ⌘X to cut the line.
  391. * alternate method: ⌘⌫, ⌃K
  392. */
  393. void VIM_DELETE_WHOLE_LINE(void) {
  394. print("\e[31md\e[0m");
  395. VIM_LEADER(KC_NO);
  396. CMD(KC_LEFT);
  397. PRESS(KC_LSFT);
  398. CMD(KC_RIGHT);
  399. RELEASE(KC_LSFT);
  400. CMD(KC_X);
  401. }
  402. /**
  403. * Vim-like `delete word` command
  404. * Simulates vim's `dw` command by sending ⌥⇧→→← then ⌘X to select to the start
  405. * of the next word then cut.
  406. */
  407. void VIM_DELETE_WORD(void) {
  408. print("\e[31mw\e[0m");
  409. VIM_LEADER(KC_NO);
  410. PRESS(KC_LALT);
  411. SHIFT(KC_RIGHT); // select to end of this word
  412. SHIFT(KC_RIGHT); // select to end of next word
  413. SHIFT(KC_LEFT); // select to start of next word
  414. RELEASE(KC_LALT);
  415. CMD(KC_X); // delete selection
  416. }
  417. /**
  418. * Vim-like `delete back` command
  419. * Simulates vim's `db` command by selecting to the end of the word then deleting.
  420. */
  421. void VIM_DELETE_BACK(void) {
  422. print("\e[31mb\e[0m");
  423. VIM_LEADER(KC_NO);
  424. PRESS(KC_LALT);
  425. SHIFT(KC_LEFT); // select to start of word
  426. SHIFT(KC_DEL); // delete selection
  427. RELEASE(KC_LSFT);
  428. }
  429. /**
  430. * Vim-like `delete left` command
  431. * Simulates vim's `dh` command by sending ⇧← then ⌘X.
  432. */
  433. void VIM_DELETE_LEFT(void) {
  434. print("\e[31mh\e[0m");
  435. VIM_LEADER(KC_NO);
  436. SHIFT(KC_LEFT);
  437. CMD(KC_X);
  438. }
  439. /**
  440. * Vim-like `delete right` command
  441. * Simulates vim's `dl` command by sending ⇧→ then ⌘X.
  442. */
  443. void VIM_DELETE_RIGHT(void) {
  444. print("\e[31ml\e[0m");
  445. VIM_LEADER(KC_NO);
  446. SHIFT(KC_RIGHT);
  447. CMD(KC_X);
  448. }
  449. /**
  450. * Vim-like `delete up` command
  451. * Simulates vim's `dk` command by sending ↑ then deleting the line.
  452. */
  453. void VIM_DELETE_UP(void) {
  454. print("\e[31mk\e[0m");
  455. VIM_LEADER(KC_NO);
  456. TAP(KC_UP);
  457. VIM_DELETE_LINE();
  458. }
  459. /**
  460. * Vim-like `delete down` command
  461. * Simulates vim's `dj` command by sending ↓ then deleting the line.
  462. */
  463. void VIM_DELETE_DOWN(void) {
  464. print("\e[31mj\e[0m");
  465. VIM_LEADER(KC_NO);
  466. TAP(KC_DOWN);
  467. VIM_DELETE_LINE();
  468. }
  469. /***
  470. * ###### ### ###### ###### ####### ####### ### # # ####### ######
  471. * # # # # # # # # # # # # # # #
  472. * # # # # # # # # # # # # # # #
  473. * # # # ###### ###### ##### ##### # # ##### # #
  474. * # # # # # # # # # # # # # #
  475. * # # # # # # # # # # # # # #
  476. * ###### ### # # # ####### # ### # # ####### ######
  477. *
  478. */
  479. /**
  480. * Vim-like `delete inner word` command
  481. * Simulates vim's `diw` command by moving back then cutting to the end of the word.
  482. */
  483. void VIM_DELETE_INNER_WORD(void) {
  484. print("\e[31mw\e[0m");
  485. VIM_LEADER(KC_NO);
  486. VIM_BACK();
  487. VIM_DELETE_END();
  488. }
  489. /***
  490. * ##### ###### ###### ####### ####### ### # # ####### ######
  491. * # # # # # # # # # # # # # #
  492. * # # # # # # # # # # # # #
  493. * # ###### ###### ##### ##### # # ##### # #
  494. * # # # # # # # # # # # #
  495. * # # # # # # # # # # # # #
  496. * ##### # # # ####### # ### # # ####### ######
  497. *
  498. */
  499. /**
  500. * Vim-like `change back` command
  501. * Simulates vim's `cb` command by first deleting to the start of the word,
  502. * then switching to insert mode.
  503. */
  504. void VIM_CHANGE_BACK(void) {
  505. print("\e[31mb\e[0m");
  506. VIM_LEADER(KC_NO);
  507. VIM_DELETE_BACK();
  508. layer_on(INSERT_MODE);
  509. }
  510. /**
  511. * Vim-like `change down` command
  512. * Simulates vim's `cj` command by sending ↓ then changing the line.
  513. */
  514. void VIM_CHANGE_DOWN(void) {
  515. print("\e[31mj\e[0m");
  516. VIM_LEADER(KC_NO);
  517. VIM_DELETE_DOWN();
  518. layer_on(INSERT_MODE);
  519. }
  520. /**
  521. * Vim-like `change to end` command
  522. * Simulates vim's `ce` command by first deleting to the end of the word,
  523. * then switching to insert mode.
  524. */
  525. void VIM_CHANGE_END(void) {
  526. print("\e[31mce\e[0m");
  527. VIM_LEADER(KC_NO);
  528. VIM_DELETE_END();
  529. layer_on(INSERT_MODE);
  530. }
  531. /**
  532. * Vim-like `change left` command
  533. * Simulates vim's `ch` command by deleting left then switching to insert mode.
  534. */
  535. void VIM_CHANGE_LEFT(void) {
  536. print("\e[31mch\e[0m");
  537. VIM_LEADER(KC_NO);
  538. VIM_DELETE_LEFT();
  539. layer_on(INSERT_MODE);
  540. }
  541. /**
  542. * Vim-like `change right` command
  543. * Simulates vim's `cl` command by deleting right then switching to insert mode.
  544. */
  545. void VIM_CHANGE_RIGHT(void) {
  546. print("\e[31mcl\e[0m");
  547. VIM_DELETE_RIGHT();
  548. layer_on(INSERT_MODE);
  549. }
  550. /**
  551. * Vim-like `change up` command
  552. * Simulates vim's `ck` command by deleting up then switching to insert mode.
  553. */
  554. void VIM_CHANGE_UP(void) {
  555. print("\e[31mck\e[0m");
  556. VIM_DELETE_UP();
  557. layer_on(INSERT_MODE);
  558. }
  559. /**
  560. * Vim-like `change word` command
  561. * Simulates vim's `cw` command by first deleting to the end of the word,
  562. * then switching to insert mode.
  563. */
  564. void VIM_CHANGE_WORD(void) {
  565. print("\e[31mcw\e[0m");
  566. VIM_LEADER(KC_NO);
  567. VIM_DELETE_WORD();
  568. layer_on(INSERT_MODE);
  569. }
  570. /***
  571. * ##### ### ###### ###### ####### ####### ### # # ####### ######
  572. * # # # # # # # # # # # # # # #
  573. * # # # # # # # # # # # # # #
  574. * # # ###### ###### ##### ##### # # ##### # #
  575. * # # # # # # # # # # # # #
  576. * # # # # # # # # # # # # # #
  577. * ##### ### # # # ####### # ### # # ####### ######
  578. *
  579. */
  580. /**
  581. * Vim-like `change inner word` command
  582. * Simulates vim's `ciw` command by deleting the inner word then switching to insert mode.
  583. */
  584. void VIM_CHANGE_INNER_WORD(void) {
  585. print("\e[31mciw\e[0m");
  586. VIM_DELETE_INNER_WORD();
  587. layer_on(INSERT_MODE);
  588. }
  589. /***
  590. * # # ###### ###### ####### ####### ### # # ####### ######
  591. * # # # # # # # # # # # # # #
  592. * # # # # # # # # # # # # # #
  593. * # # ###### ###### ##### ##### # # ##### # #
  594. * # # # # # # # # # # # # #
  595. * # # # # # # # # # # # # #
  596. * # # # # ####### # ### # # ####### ######
  597. *
  598. */
  599. /**
  600. * Vim-like `visual select back` command
  601. * Simulates vim's `vb` command by selecting to the enc of the word.
  602. */
  603. void VIM_VISUAL_BACK(void) {
  604. print("\e[31mvb\e[0m");
  605. VIM_LEADER(KC_NO);
  606. PRESS(KC_LALT);
  607. SHIFT(KC_LEFT); // select to start of word
  608. RELEASE(KC_LALT);
  609. }
  610. /**
  611. * Vim-like `visual select to end` command
  612. * Simulates vim's `ve` command by selecting to the end of the word.
  613. */
  614. void VIM_VISUAL_END(void) {
  615. print("\e[31mve\e[0m");
  616. VIM_LEADER(KC_NO);
  617. PRESS(KC_LALT);
  618. SHIFT(KC_RIGHT); // select to end of this word
  619. RELEASE(KC_LALT);
  620. }
  621. /**
  622. * Vim-like `visual select word` command
  623. * Simulates vim's `vw` command by selecting to the end of the word.
  624. */
  625. void VIM_VISUAL_WORD(void) {
  626. print("\e[31mvw\e[0m");
  627. VIM_LEADER(KC_NO);
  628. PRESS(KC_LALT);
  629. SHIFT(KC_RIGHT); // select to end of this word
  630. SHIFT(KC_RIGHT); // select to end of next word
  631. SHIFT(KC_LEFT); // select to start of next word
  632. RELEASE(KC_LALT);
  633. }
  634. /**
  635. * Vim-like `visual left` command
  636. * Simulates vim's `vh` command by sending ⇧←.
  637. */
  638. void VIM_VISUAL_LEFT(void) {
  639. print("\e[31mvh\e[0m");
  640. VIM_LEADER(KC_NO);
  641. SHIFT(KC_LEFT);
  642. }
  643. /**
  644. * Vim-like `visual right` command
  645. * Simulates vim's `vl` command by sending ⇧→.
  646. */
  647. void VIM_VISUAL_RIGHT(void) {
  648. print("\e[31mvl\e[0m");
  649. VIM_LEADER(KC_NO);
  650. SHIFT(KC_RIGHT);
  651. }
  652. /**
  653. * Vim-like `visual up` command
  654. * Simulates vim's `vk` command by sending ⇧↑.
  655. */
  656. void VIM_VISUAL_UP(void) {
  657. print("\e[31mvk\e[0m");
  658. VIM_LEADER(KC_NO);
  659. SHIFT(KC_UP);
  660. }
  661. /**
  662. * Vim-like `visual down` command
  663. * Simulates vim's `vj` command by sending ⇧↓.
  664. */
  665. void VIM_VISUAL_DOWN(void) {
  666. print("\e[31mdj\e[0m");
  667. VIM_LEADER(KC_NO);
  668. SHIFT(KC_DOWN);
  669. }
  670. /***
  671. * # # ### ###### ###### ####### ####### ### # # ####### ######
  672. * # # # # # # # # # # # # # # #
  673. * # # # # # # # # # # # # # # #
  674. * # # # ###### ###### ##### ##### # # ##### # #
  675. * # # # # # # # # # # # # # #
  676. * # # # # # # # # # # # # # #
  677. * # ### # # # ####### # ### # # ####### ######
  678. *
  679. */
  680. /**
  681. * Vim-like `visual inner word` command
  682. * Simulates vim's `viw` command by moving back then selecting to the end of the word.
  683. */
  684. void VIM_VISUAL_INNER_WORD(void) {
  685. print("\e[31mviw\e[0m");
  686. VIM_LEADER(KC_NO);
  687. VIM_BACK();
  688. VIM_VISUAL_END();
  689. }