Ok, so this is my first post.
I too have an ergodox, but my control and alt are mapped to where CAPS and L-Shift are respectively. However, I still prefer avoiding chords. It got me thinking though, if the reason we love vim, evil/god-mode, and kakoune is the idea of modal editing, why not extend that model?
Word Mode
declare-user-mode word
map global normal w ':enter-user-mode -lock word<ret>'
map global word w w -docstring 'select to next word start'
map global word W W -docstring 'extend to next word start '
map global word b b -docstring 'select to previous word start'
map global word B B -docstring 'extend to previous word start'
map global word e e -docstring 'select to next word end'
map global word E E -docstring 'extend to next word end'
map global word q <a-w> -docstring 'select to next WORD start'
map global word Q <a-W> -docstring 'extend to next WORD start'
map global word v <a-b> -docstring 'select to previous WORD start'
map global word V <a-B> -docstring 'extend to previous WORD start'
map global word r <a-e> -docstring 'select to next WORD end'
map global word R <a-E> -docstring 'extend to next WORD end'
def -hidden select-next-subword %{
exec /[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>
}
def -hidden extend-next-subword %{
exec ?[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>
}
def -hidden select-prev-subword %{
exec <a-/>[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>
}
def -hidden extend-prev-subword %{
exec <a-?>[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>
}
map global word s :select-next-subword<ret> -docstring 'select to next subword'
map global word S :extend-next-subword<ret> -docstring 'extend to next subword'
map global word a :select-prev-subword<ret> -docstring 'select to previous subword'
map global word A :extend-prev-subword<ret> -docstring 'extend to previous subword'
Whenever I start moving around with w
, b
, and e
, I don’t usually do a one off word-wise movement, but rather execute a few in succession before finally editing text. w
locks the user into a word-mode, thanks to Kakoune’s -lock
flag. It’s a bit harder to get mnemonic mappings, but not all keybindings have to be mnemonic. In this example, they’re spatially related. v
and V
are mapped to <a-b>
and <a-B>
, respectively, as an example.
We can now enhance “word-mode” without needing to come up with akward chords a la emacs or excessive keystrokes a la spacemacs. So for instance, in my example, I added subword movements, courtesy of Alex. The entire keyboard freed up for us to add one-key-press movements. That’s powerful.
We just freed up W
, <a-w>
, <a-W>
, e
, E
, b
, B
, <a-e>
, <a-E>
, <a-b>
, <a-B>
. This starts giving us more economy in the long run, because b/B
can now be mapped to buffer operations, for example, as suggested by @Delapouite
Other potential modes
How about a line mode? C-l
can enter line mode, then j
and k
and move lines. o
and O
can add lines after/before. You can now freely add options to select line excluding leading/trailing whitespaces.
How about a buffer mode? Trigger with b
. n
and p
cycle between buffers.
Paragraph mode! In vim I used to enjoy {
and }
movement, which moves to the next/prev empty line. Kak needs [p
and ]p
. [p
doesn’t even go to the empty line. j
and k
can transpose paragraphs up/down?
Brace mode? Now it should be easier to expand, inner block, outer block, etc;
Economics
Determining whether a mode should exist would largely depend on the average amount of related key presses. Something like a “window-mode” probably wouldn’t make sense because if you execute new-window
, you’re probaby just doing it once. However, maybe that’s just a limit of my imagination.
Enhancements to kakoune to make custom user modes more powerful
All this said, my current implementation of a “word-mode” isn’t as comfortable as I would like. There are several new features that can make this work better. Some more essential, while others being more experimental;
-
Passthrough option - Perhaps a
-passthrough
flag which lets keys not defined in your user mode to act like normal mode keys.
-
Exclude keys option - Define specific keys for passthrough. If the passthrough flag is used, then the opposite effect is achieved; keys do are blocked from passing through.
-
One shot binding in lock mode - Ideally, some mechanism would exist to designate certain keys to execute and leave the mode. This could either be a command like
:exit-user-mode
or a flag like map global _word_ -leave d ':do-something<ret>'
-
Mode stacks - One idea we can experiment is having modes stack on top of each other, either through config or keybindings. While I can’t think of any uses right now, it’s something that can be explored.
Conclusion
I don’t think I mentioned anything revolutionary here. It’s been stated by others in various other ways and these ideas already exist. Hopefully I was able to summarize these concepts in a useful way and present ways to enhance the kakoune program to make modal editing even more advanced.