Avoiding modifier chording

I’ve been noticing that, even though Kakoune uses less keystrokes, they are often more awkward. For example, Shift+Alt+C (which doesn’t seem to work for me anyway), requires me to use right Alt and right Shift. I’m really happy with the structural regex stuff and the order of operations, so I’m not leaving Kakoune, but I’m wondering what to do about it…

The ideas I have so far are to introduce user modes. I can do one for “extend selection”, which I guess is just kind of like Caps Lock, which is pretty much like v. Hmm, that’s pretty cheap. I’ll try that.

The other idea would be a new one-shot mode for Alt. This could be either my keyboard or a Kakoune user-mode mapping. This still feels awkward.

Some interesting background: Since getting my ErgoDox, I’ve trained myself to use left and right control, and left and right shift correctly. This is kind of not normal, I know (the MacBook keyboard doesn’t have a right control!), but it’s very nice on an ortholinear keyboard. It means I never have to reach and pivot my hands the way I used to for like, Ctrl+C and Ctrl+X (and this was the thing that made emacs so painful when I first tried it, which is why I started using Vim in like 2000).

This works flawlessly 95% of the time. There are times when it doesn’t, like when I’m pairing with a colleague using emacs and I need to type <c-c><c-k>, which is right-ctrl C, left-ctrl K. I tend to type the left and right ctrl keys overlapping, which confuses my ErgoDox (since the control keys are dual-purpose).

I absolutely agree – in Vim I avoided any use a chording because I loathe it. I have accepted a lot more of it in Kakoune, but I don’t love it here either. I very often used <a-i> and I don’t love it. The one shot mode, or even just like alt-toggle mode – sort of reminds me of god-mode in emacs.

1 Like

Some random ideas how to avoid shift/alt chords:

Spacemacs like mode

There’s no much room left in normal mode, even when you count chords. Spacemacs has a lot functionality hidden under <space> leader key, and it’s easy to do this in Kakoune:

map global normal <space> ,
map global mymode <space> <space> #double space to deselect

Boom, you have new, easily accessible “normal” mode. Space is big, easy to hit and usually you don’t do much with your thumbs. First keys I’d bind in such mode are inner/outer object selection.

Plugins

Those two plugins are perfect combo. Vertical selection will replace C in many cases. Text object is probably my favorite plugin (just before kakoune-auto-percent). Take a look at selector mode - it’s might be what you are looking for.

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.

2 Likes

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.

Kakoune already has the concept of stacking modes, at least for insert and normal modes.If you start in normal mode and type i<a-;>i, you wind up with a stack of four modes:

  • the regular base normal mode
  • insert mode
  • a temporary normal mode that exits after one command
  • another insert mode

Unfortunately, user modes (in the sense of declare-user-mode and enter-user-mode) don’t currently participate in the mode stack for historical reasons (see #2569), which means that (among other things) you can’t put <esc> in a user mode mapping to exit the mode, even though that works in an insert mode mapping.

I like the idea of a passthrough option, but I wonder how it would work with mappings in outer modes. For example, if mode X had a mapping with an <esc> to exit mode X, and you activated mode Y on top with passthrough, then you pressed the mode X mapping, would the <esc> exit mode Y instead? Or both X and Y?

Yeah, passthrough might get complicated. I think the preferred alternative is the leave-user-mode option. Or better yet, the ability to call “enter-normal-mode” or enter any user mode from any user mode. I also think that specifying custom keys for passthrough or block would get ugly in terms of syntax, whereas a simple leave-user-mode will fit right in with the current flow.

I used to have an implementation (I got rid of it because the “helper” was more annoying than setting up shortcuts) of a mode with passthrough in gdb.kak. It was back when user-mode didn’t exist.
It’s a bit hacky, so I’m not sure if you want to do this

I find following amendment of view mode pretty helpful to avoid <a-i><a-a> chords:

map global view i <esc><a-i> -docstring "<a-i>"
map global view a <esc><a-a> -docstring "<a-a>"
2 Likes

When you think about it, <a-i> and <a-a> choice was mostly motivated by vim’s legacy which uses i and a operators in sequence like diw (delete inside word) or cap (change around paragraph).

So in Kakoune we still follow a similar mnemotechnic:

  • i → inside
  • a → around

A few months ago I’ve experimented with the following change: using o instead of a. In this case o can stand for “outside”.
The big advantage on a qwerty keyboard is that i and o are neighbors keys, both under your right hand. So in your case:

map global view i <esc><a-i> -docstring "<a-i>"
map global view o <esc><a-a> -docstring "<a-a>"

Which means left finger on v and then right hand fingers for i or o.

1 Like

Bumping the thread to get more information about users’ typing habits. You write that you very often use <a-i> and dislike it, but you do not mention <a-a>. May I infer that you use inner object selection more than outer object selection? And, out of curiosity, what are the inner objects that you more often select with <a-i>? Indent and paragraph, maybe?

Paragraph and line content with x from @Delapouite.

Also word, but I do not count it because I use word-select.kak.

I also use <a-i> more often than <a-a>. I mostly use it with parenthesis and to select current indentation.

Hm, actually I use more often <a-a> with p, but <a-i> with parenthesis and indent too.

Since using ErgoDox, you might want to have a look at: https://kaleidoscope.readthedocs.io/en/latest/plugins/Qukeys.html — discovered them today. They are fantastic!!

I would be interested in your feedback after a few days of usage.

I remember trying a similar strategy in the past for long press on caps lock = ctrl, short press on caps lock = esc, but I experienced quite a few false positives. For example once in a while I wanted to do a short press, but my stubborn fingers where pressing a little bit longer that expected. So in the end, I had to disable this behavior because I had hard to make it work as intended 100% of the time.
Maybe it was my lack of practice.

I have made a few (thumb) tests and tried very hard to overlap (intended) normal keystrokes of the qukeys in order to trigger a false positive for the modifier behavior:

  • a/s/h/t (workman) Ctrl/Shift/Alt/Cmd

I could only generate false positives if literally cram them all at once into very few ms: “ash”.

So the risk is only real if a word uses adjacent qukeys in a row so same hand fingers could easily strike them at once (similar as a typewriter could get clogged on adjacent levers).

I think it’s almost impossible to get false positives when some horizontal finger movement is involved or if it’s a two hand sequence.

I don’t think it’s a problem, but if it should become one, I would opt to put (querty) “sd” onto “we” (like the second most ergonomic position for middle and ring finger) so to penalize a little on the possibility of cramming. (sh -> dr / workman)

Here is a just published, very in depth article about using home row modifier keys: https://precondition.github.io/home-row-mods

It talks about the benefits, necessary configuration you need to avoid false triggers and alternatives. I personally use overloaded thumb keys rather than home row keys but this article might convince me to give it a shot. Thumb keys are at a premium when working with only 36 keys!

4 Likes

Thanks! This article is very comprehensive. The true revelation for me is that it looks like this approach does not require a mechanical keyboard with QMK firmware but can be emulated on the software side with https://github.com/david-janssen/kmonad

I’ll definitely investigate this road as nowadays I mostly type on laptop keyboards all day long.

Honestly this could make kakoune more fun to use, considering how it heavily relies on shift and alt modifiers.

I happen to use Planck which has programmable QMK firmware, so might as well implement this at keyboard firmware level!

Has anyone modifier one home row ? I’m curious to know how reliable it is