Useful user-modes

Hey all,

I’m starting to get more comfortable with using Kakoune, and with that comes more configuration! I wanted to use this thread as a place to share some useful user-modes. feel free to post yours.

1 Like

Hello. I’ve started to gather a few user-modes here : https://github.com/Delapouite/kakoune-user-modes/blob/master/user-modes.kak

Another interesting one that let you shrink, grow selections symmetrically: https://github.com/Delapouite/kakoune-mirror

I declare a user mode for dealing with Git workflows…some commands which act as shortcuts for the built-in Git support, and others that shell out to tig for more complex functionality:

map global user -docstring "Enable Git keymap mode for next key" g ": enter-user-mode<space>git<ret>"

declare-user-mode git
map global git -docstring "blame - Show what revision and author last modified each line of the current file" b ': repl tig blame -C "+%val{cursor_line}" -- "%val{buffile}"<ret>'
map global git -docstring "commit - Record changes to the repository" c ": git commit<ret>"
map global git -docstring "diff - Show changes between HEAD and working tree" d ": git diff<ret>"
map global git -docstring "git - Explore the repository history" g ": repl tig<ret>"
map global git -docstring "github - Copy canonical GitHub URL to system clipboard" h ": github-url<ret>"
map global git -docstring "log - Show commit logs for the current file" l ': repl tig log -- "%val{buffile}"<ret>'
map global git -docstring "prompt - Run a free-form Git command prompt" p ":repl tig "
map global git -docstring "status - Show the working tree status" s ": repl tig status<ret>"
map global git -docstring "staged - Show staged changes" t ": git diff --staged<ret>"
map global git -docstring "write - Write and stage the current file" w ": write<ret>: git add<ret>: git update-diff<ret>"

…and the source for the github-url function can be found here: https://github.com/elasticdog/dotfiles/blob/ddba2788c9d79912ccf352c3f5ada908e196ba87/kakoune/.config/kak/kakrc#L194-L223

I’m excited to poke through other people’s user modes as well…great idea for a thread!

4 Likes

@TeddyDD has a nice spell user-mode:

declare-user-mode spell
map global spell p ': spell pl<ret>' -docstring 'PL'
map global spell e ': spell en<ret>' -docstring 'ENG'
map global spell f ': spell-next<ret>_: enter-user-mode spell<ret>' -docstring 'next'
map global spell s ': spell-replace<ret><ret> : enter-user-mode spell<ret>' -docstring 'lucky fix'
map global spell a ': spell-replace<ret>' -docstring 'manual fix'
map global spell c ': spell-clear<ret>' -docstring 'clear'

Damnit @Delapouite… what key to I bind this to! I got g for git and s for search… and now we have spell, I think I am going to maybe use g and G for search and Git. s for spell.

@elasticdog I love the copy/paste to system stuff you had, I actually made that a user mode too (found it to support your github-url)

Glad you found it useful! I forgot that my github-url setup relied on that clipboard handling. It was mostly stolen directly from @mawww’s dotfiles: https://github.com/mawww/config/blob/8fe6034c524a3d75a648e361abe7095a444c7a2f/kakrc#L61-L74

Oh nice! I’ve been meaning to implement something like your lucky fix for spellcheck corrections. Thanks for posting this.

Recipes can be a nice alternative to explore for a crowded user mode. I think I prefer them for non-editing features like Git and spelling.