├── README.md └── mirror.kak /README.md: -------------------------------------------------------------------------------- 1 | # kakoune-mirror 2 | 3 | [kakoune](http://kakoune.org) plugin to grow / shrink selections in both directions or surround them. 4 | 5 | ## Install 6 | 7 | Add `mirror.kak` to your autoload dir: `~/.config/kak/autoload/`. 8 | 9 | Or via [plug.kak](https://github.com/andreyorst/plug.kak): 10 | 11 | ``` 12 | plug 'delapouite/kakoune-mirror' %{ 13 | # Suggested mapping 14 | map global normal "'" ': enter-user-mode -lock mirror' 15 | } 16 | ``` 17 | 18 | ## Usage 19 | 20 | This plugin provides a `mirror` user-mode. 21 | 22 | For example with the above mapping, press `'` to enter the mirror mode (`` to leave). 23 | 24 | ### Grow / shrink 25 | 26 | If you type `l` it grows the selections one char to their right, but also one char to their left. 27 | To shrink it one char, use `h`. 28 | When the cursor is before the anchor, it does the opposite. 29 | 30 | **Example**: the current selection is the middle `l`. Typing `'llhh` would produce these visual steps: 31 | ``` 32 | he[l]lo 33 | h[ell]o 34 | [hello] 35 | h[ell]o 36 | he[l]lo 37 | ``` 38 | 39 | You can also use `w` to grow one word to the right and it automatically do a `b` on the left. 40 | 41 | It works vertically with `j` and `k`. Or `J` and `K` for full lines. 42 | Hitting `c` will expand by columns above and below. 43 | 44 | Finally you can also do it for paragraphs or sentences with `p` and `s`. 45 | 46 | ### Surround 47 | 48 | Pairwise characters like braces, brackets or quotes can be added, replaced or removed. 49 | 50 | **Example**: starting from the world `hello` selected. 51 | 52 | First, let's surround it with double quotes and parentheses `'"(` 53 | 54 | ``` 55 | [hello] 56 | ["hello"] 57 | [("hello")] 58 | ``` 59 | 60 | Oops, you meant to surround the double quotes with spaced-braces! Press `d` to remove the parens, then `}` 61 | 62 | ``` 63 | ["hello"] 64 | [{ "hello" }] 65 | ``` 66 | 67 | ## See Also 68 | 69 | - [kakoune-expand](https://github.com/occivink/kakoune-expand) 70 | - [kakoune-text-objects](https://github.com/Delapouite/kakoune-text-objects) 71 | - [kakoune-surround](https://github.com/h-youhei/kakoune-surround) 72 | - [move-line.kak](https://github.com/alexherbo2/move-line.kak) 73 | - [auto-pairs.kak](https://github.com/alexherbo2/auto-pairs.kak) 74 | - [surround.kak](https://github.com/alexherbo2/surround.kak) 75 | 76 | ## Licence 77 | 78 | MIT 79 | -------------------------------------------------------------------------------- /mirror.kak: -------------------------------------------------------------------------------- 1 | declare-user-mode mirror 2 | 3 | # grow/shrink 4 | map global mirror c 'C' -docstring column 5 | map global mirror h 'HL' -docstring character 6 | map global mirror l 'LH' -docstring character 7 | map global mirror j 'JK' -docstring line 8 | map global mirror k 'KJ' -docstring line 9 | map global mirror J 'JK' -docstring 'full line' 10 | map global mirror K 'KJ' -docstring 'full line' 11 | map global mirror b 'BW' -docstring 'word begin' 12 | map global mirror w 'WB' -docstring 'word begin' 13 | map global mirror e 'EB' -docstring 'word end' 14 | map global mirror p '}p{p' -docstring paragraph 15 | map global mirror s '}s{s' -docstring sentence 16 | map global mirror m 'M' -docstring matching 17 | 18 | # insert/delete 19 | map global mirror ( 'a)i(H' -docstring '(surround)' 20 | map global mirror { 'a}i{H' -docstring '{surround}' 21 | map global mirror [ 'a]i[H' -docstring '[surround]' 22 | map global mirror < 'aiH' -docstring '' 23 | map global mirror « 'a»H' -docstring '«surround»' 24 | map global mirror ) 'a )i( 2H' -docstring '( surround )' 25 | map global mirror } 'a }i{ 2H' -docstring '{ surround }' 26 | map global mirror ] 'a ]i[ 2H' -docstring '[ surround ]' 27 | map global mirror > 'a i 2H' -docstring '< surround >' 28 | map global mirror » 'a »2H' -docstring '« surround »' 29 | map global mirror '"' 'a"i"H' -docstring '"surround"' 30 | map global mirror "'" "a'i'H" -docstring "'surround'" 31 | map global mirror '`' 'a`i`H' -docstring '`surround`' 32 | map global mirror d 'ZzH' -docstring 'delete' 33 | 34 | # fallthrough 35 | map global mirror '' '' -docstring 'swap anchor and cursor' 36 | map global mirror '' '' -docstring 'select sels boundaries' 37 | 38 | # Suggested mapping 39 | 40 | #map global normal "'" ': enter-user-mode -lock mirror' -docstring 'mirror lock' 41 | --------------------------------------------------------------------------------