├── LICENSE ├── README.md └── readline.kak /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Gregory L. Chamberlain 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Readline-style mappings for Kakoune 2 | 3 | This plugin implements many line-editing shortcuts in 4 | [Kakoune](https://kakoune.org), emulating 5 | [Readline](http://www.gnu.org/software/readline/) as 6 | closely as possible. See the readline(1) man page for explanations of 7 | what they do. 8 | 9 | ## Installation 10 | 11 | ### Using `plug.kak` 12 | 13 | Suggested configuration: 14 | 15 | ``` kak 16 | # ~/.config/kak/kakrc 17 | plug chambln/kakoune-readline config %{ 18 | map global insert 19 | map global insert 20 | map global insert 21 | map global insert 22 | hook global WinCreate .* readline-enable 23 | } 24 | ``` 25 | 26 | Use `` to insert a tab character; or omit the config clause if 27 | you’d rather not use tab for completion. 28 | 29 | ### Manual 30 | 31 | Put a copy of or link to `readline.kak` anywhere within your 32 | `~/.config/kak/autoload/` directory. 33 | 34 | ### Usage 35 | 36 | Manually enable Readline mappings in the current window: 37 | 38 | :readline-enable 39 | 40 | Enable Readline mappings for the `sh` filetype: 41 | 42 | ``` kak 43 | # ~/.config/kak/kakrc 44 | hook global WinSetOption filetype=sh %{ 45 | readline-enable 46 | hook window WinSetOption filetype=.* readline-disable 47 | } 48 | ``` 49 | 50 | Always use Readline mappings: 51 | 52 | ``` kak 53 | # ~/.config/kak/kakrc 54 | hook global WinCreate .* readline-enable 55 | ``` 56 | 57 | ## To-do 58 | 59 | - Implement `reverse-search-history (C-r)` and `forward-search-history 60 | (C-s)`. 61 | - Maybe respect `%opt{extra_word_chars}`? 62 | 63 | ## Bugs and notes 64 | 65 | - `` kills two words backward if the cursor is exactly one 66 | character into the latter, e.g. `one two t|hree four` becomes `one 67 | |hree four` where `|` represents the cursor. 68 | 69 | - `transpose-char` and `transpose-word` traverse line breaks. 70 | 71 | - If the cursor is in the middle of the word, 72 | `delete-horizontal-space` deletes whitespace after it. 73 | 74 | - The `` (`unix-line-discard`) mapping overrides Kakoune’s 75 | default: 76 | 77 | 78 | commit changes up to now as a single undo group 79 | -------------------------------------------------------------------------------- /readline.kak: -------------------------------------------------------------------------------- 1 | # See LICENSE file for copyright and license details. 2 | 3 | provide-module readline %{ 4 | 5 | define-command -hidden readline-forward-word %{ 6 | # Expects to be called from insert mode. 7 | try %{ 8 | execute-keys './[a-zA-Z0-9]+' 9 | } 10 | } 11 | 12 | define-command -hidden readline-backward-word %{ 13 | # Expects to be called from insert mode. 14 | try %{ 15 | execute-keys '[A-Za-z0-9]+;' 16 | } 17 | } 18 | 19 | define-command -hidden readline-unix-word-rubout %{ 20 | # Expects to be called from insert mode. 21 | try %{ 22 | execute-keys '\S+\s*d' 23 | } 24 | } 25 | 26 | define-command -hidden readline-transpose-chars %{ 27 | # Expects to be called from insert mode. 28 | execute-keys ';' 29 | try %{ 30 | execute-keys 's$' # Fail unless cursor is at line end. 31 | execute-keys 'dp' # Transpose characters at line end. 32 | } catch %{ 33 | execute-keys 's^.' # Fail unless cursor is at line start. 34 | execute-keys 'dP' # Move character to end of line above. 35 | } catch %{ 36 | execute-keys 'dp' # Transpose characters. 37 | } 38 | } 39 | 40 | define-command -hidden readline-transpose-words %{ 41 | # Expects to be called from insert mode. 42 | readline-forward-word 43 | execute-keys -itersel '[^A-Za-z0-9]+s[A-Za-z0-9]+)' 44 | } 45 | 46 | define-command readline-enable %{ 47 | map window insert -docstring beginning-of-line 48 | map window insert -docstring end-of-line 49 | map window insert -docstring forward-char 50 | map window insert -docstring backward-char 51 | map window insert ': readline-forward-word' -docstring forward-word 52 | map window insert ': readline-backward-word' -docstring backward-word 53 | map window insert 'vt' -docstring clear-screen 54 | map window insert -docstring delete-char 55 | map window insert -docstring backward-delete-char 56 | map window insert -docstring quoted-insert 57 | map window insert ': execute-keys tab' -docstring tab-insert 58 | map window insert ': readline-transpose-chars' -docstring transpose-chars 59 | map window insert ': readline-transpose-words' -docstring transpose-words 60 | map window insert ';W~' -docstring upcase-word 61 | map window insert ';W`' -docstring downcase-word 62 | map window insert ';~W`' -docstring capitalize-word 63 | map window insert ';Gl"_d' -docstring kill-line 64 | map window insert ';hGh"_d' -docstring unix-line-discard 65 | map window insert ';E"_d' -docstring kill-word 66 | map window insert 'B"_d' -docstring backward-kill-word 67 | map window insert 'B"_d' -docstring backward-kill-word 68 | map window insert ': readline-unix-word-rubout' -docstring unix-word-rubout 69 | map window insert 'c' -docstring delete-horizontal-space 70 | map window insert '"' -docstring yank 71 | map window prompt '"' -docstring yank 72 | map window prompt -docstring abort 73 | map window insert ': comment-line' -docstring insert-comment 74 | map window insert -docstring vi-editing-mode 75 | } 76 | 77 | define-command readline-disable %{ 78 | unmap window insert 79 | unmap window insert 80 | unmap window insert 81 | unmap window insert 82 | unmap window insert ': readline-forward-word' 83 | unmap window insert ': readline-backward-word' 84 | unmap window insert 'vt' 85 | unmap window insert 86 | unmap window insert 87 | unmap window insert 88 | unmap window insert ': execute-keys tab' 89 | unmap window insert ': readline-transpose-chars' 90 | unmap window insert ': readline-transpose-words' 91 | unmap window insert ';W~' 92 | unmap window insert ';W`' 93 | unmap window insert ';~W`' 94 | unmap window insert ';Gl"_d' 95 | unmap window insert ';hGh"_d' 96 | unmap window insert ';E"_d' 97 | unmap window insert 'B"_d' 98 | unmap window insert 'B"_d' 99 | unmap window insert ': readline-unix-word-rubout' 100 | unmap window insert 'c' 101 | unmap window insert '"' 102 | unmap window prompt '"' 103 | unmap window prompt 104 | unmap window insert ': comment-line' 105 | unmap window insert 106 | } 107 | 108 | } 109 | 110 | require-module readline 111 | --------------------------------------------------------------------------------