Anchor mode


#1
declare-user-mode anchor

map global anchor a '<esc><a-;>;'     -docstring 'reduce to anchor'
map global anchor c '<esc>;'          -docstring 'reduce to cursor'
map global anchor f '<esc><a-;>'      -docstring 'flip cursor and anchor'
map global anchor h '<esc><a-:><a-;>' -docstring 'ensure anchor after cursor'
map global anchor l '<esc><a-:>'      -docstring 'ensure cursor after anchor'
map global anchor s '<esc><a-S>'      -docstring 'select cursor and anchor'

map global normal ';' ': enter-user-mode anchor<ret>'

Nothing fancy but I find these shortcuts more complete and easier to memorize than the native ;, <a-;> and <a-:> trio.

I feel like sometimes it’s better to sacrifice one direct access key (; in this case) to open up a whole new sub mode of related commands.


#2

I often find the same, and I tend to prefer modes to modifiers as they feel more pleasing to my hands.


#3

Saved as anchor-ops.kak. However …

… I had to quote the ; to avoid a syntax error at startup; Kakoune sees the ; as the end of the statement and complains about “insufficient arguments to command”.


#4

Sorry about that. I use a different enter-key and I just changed it to ; for consistency with the default layout before pasting here.


#5

I like the command you added to ensure selections are in backward direction.

However, I’m not convinced with the command to reduce selections to their anchor. Although I understand the convenience due to a non direct access for flipping, it feels like it misses one step, or a visual effect to sound natural.


#6

Nice, I’ve adopted it


#7

I’ve found that with locking, there is no need to remember mode’s keys. Also extended it with kind of undo key, which restores original selection:

declare-user-mode anchor
map global anchor a '<a-;>;'     -docstring 'reduce to anchor'
map global anchor c ';'          -docstring 'reduce to cursor'
map global anchor f '<a-;>'      -docstring 'flip cursor and anchor'
map global anchor h '<a-:><a-;>' -docstring 'ensure anchor after cursor'
map global anchor l '<a-:>'      -docstring 'ensure cursor after anchor'
map global anchor s '<a-S>'      -docstring 'select cursor and anchor'
map global anchor u 'z'          -docstring 'restore selection'

map global normal ':' 'Z: enter-user-mode -lock anchor<ret>'