Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select multiple lines going upwards on Kakoune?

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.

like image 945
fiatjaf Avatar asked May 27 '17 18:05

fiatjaf


2 Answers

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.

like image 127
superseed Avatar answered Nov 15 '22 18:11

superseed


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>"
like image 45
Eric S. Bullington Avatar answered Nov 15 '22 17:11

Eric S. Bullington