vim.h 18 KB

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