How do I select multiple lines going upwards on Kakoune?
Asked Answered
J

2

6

In Vim I would enter visual mode with V then just move the cursor up (with k).

In kak I can select a line with x and I can extend the selection downwards by pressing X multiple times or by moving the cursor down while still pressing shift with J, but if I go up while still pressing shift, with K I keep the selection, but not for the entire line, the selection on the first selected line somehow jumps to column 0.

Jonathanjonathon answered 27/5, 2017 at 18:47 Comment(0)
E
5

It's not ideal, but at this point the best I can find to make full-line selections up is to do what you've described: x and then scroll up by pressing shiftk.

Only once you've finished scrolling up, you must then expand the selection to include all full lines by pressing altx.

See the discussion in this Github kakoune issue for some great scripting solutions to this problem that you can add to your kakrc.

One of those solutions is featured on the kakoune wiki:

def -hidden -params 1 extend-line-down %{
  exec "<a-:>%arg{1}X"
}
def -hidden -params 1 extend-line-up %{
  exec "<a-:><a-;>%arg{1}K<a-x>"
}
map global normal x ":extend-line-down %val{count}<ret>"
map global normal X ":extend-line-up %val{count}<ret>"
Evacuee answered 29/5, 2017 at 17:2 Comment(0)
P
12

That's because Kakoune's selections are oriented. When you select a line with x, the cursor is at the end of the line and the anchor at the beginning. shiftk means "extend the selection to the character above", but extend mean "select to there while keeping the same anchor" and the "character above" is the last character of the previous line.

In short, you need to switch the direction of the selection before extending up: x + alt; + shiftk.

Palua answered 17/11, 2017 at 12:45 Comment(3)
alt+; does nothing for me —I'm on macOS 10.14.3 with Kakoune v2019.01.20. Any thoughts?Autrey
I believe this is a macOS terminal quirk unrelated to Kakoune. Depending on your terminal you might want to check its settings to ensure that the option key is really alt (meta).Palua
Ahh, I see. Thanks, @superseed.Autrey
E
5

It's not ideal, but at this point the best I can find to make full-line selections up is to do what you've described: x and then scroll up by pressing shiftk.

Only once you've finished scrolling up, you must then expand the selection to include all full lines by pressing altx.

See the discussion in this Github kakoune issue for some great scripting solutions to this problem that you can add to your kakrc.

One of those solutions is featured on the kakoune wiki:

def -hidden -params 1 extend-line-down %{
  exec "<a-:>%arg{1}X"
}
def -hidden -params 1 extend-line-up %{
  exec "<a-:><a-;>%arg{1}K<a-x>"
}
map global normal x ":extend-line-down %val{count}<ret>"
map global normal X ":extend-line-up %val{count}<ret>"
Evacuee answered 29/5, 2017 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.