Annoyances when migrating from Vim

Hi all,

Having used Kakoune for about two weeks time now, I really like the visual approach. Coming from Vim though, I’ve a couple of annoyances maybe someone could clarify or give a solution to.

  1. How do you quickly jump around in a line? I’m used to hitting f to find a char and replace it by a another one using r. Kakoune selects a region when using f or t, so it forces me to use ; after every jump to narrow my selection before doing a change or replace command. Is there a quicker way?

  2. Along the same lines: when changing/deleting to a certain char, I hit f to find the spot. However, it could be the first jump is not far enough. I can repeat the command using <a-.>, but then Kakoune selects a new region instead of extending the existing one. Is there a better way?

  3. <a-h> does not do the same thing as ^ in Vim. I’d like a way to select to the first non blank character on a line and operate on it.

  4. What is the equivalent of Vim’s 2cc in Kakoune? If I hit 2Xc (which, alas, is not as quick to hit as 2cc), Kakoune deletes 2 lines including the line end and starts insert mode at column 0 with the contents of the next line after the cursor. I find this particularly annoying for a couple of reasons:

    • Kakoune does not take into account the indentation of the surrounding lines.
    • The line I’m editing is polluted with the contents of the next line which moves along when I type.
    • I have to hit return after my changes to re-enter the end of line which was deleted.
    • There is the fact that 2Xc or 2Xd might delete three lines when my cursor happend to be on an empty line, which I find really inconsistent…
3 Likes

hl is more keys that ;, but they’re keys directly under my fingertips.

Gi

That’s Shift-G to open the goto menu in “extend selection” mode, and i for “first non-blank character”.

I’ve learned to make selections and so forth visually. That is, I don’t count two lines and type a 2 before the command, I just bounce on the X key until I can see that all the text I wanted to select is selected. Maybe that’s two presses, maybe that’s three presses, whatever it takes.

1 Like

; should also be directly under your finger, no?

Not on a Dvorak keyboard.

Admittedly l is also not on the home-row for Dvorak, but it’s a key I use an awful lot more than ;, so I’m more in the habit of hitting it.

hl is more keys that ; , but they’re keys directly under my fingertips.

Although it is under my fingers, it is more keys to hit to make a correction I don’t wanne make.

Gi. That’s Shift-G to open the goto menu in “extend selection” mode, and i for “first non-blank character”.

Thanks, that does the trick!

I’ve learned to make selections and so forth visually. That is, I don’t count two lines and type a 2 before the command, I just bounce on the X key until I can see that all the text I wanted to select is selected. Maybe that’s two presses, maybe that’s three presses, whatever it takes.

It really does not make a difference for my reasoning between hitting 2Xc or XXc, the effect is the same. That means that Kakoune still

  • puts me in column 0,
  • deletes the end of line,
  • requires me to correct that afterwards, and
  • is not consistent in deleting 2 or 3 lines depending on the line to be empty or not.

Additionally: how do I correct my selection when my fingers selected an extra line? There is no “deselect line” motion as B is for W

Your common case is one off typos?

Yeah, I know that feeling. Sometimes, editing text with Kakoune feels a little bit like playing Snake, since you have to think about where the anchor is as well as the cursor.

I use K for this. It’s not a complete “undo” since X moves to the end of the following line while K does not move to the end of the previous line, but manually adjusting the end of the selection is usually easier than deselecting everything and starting from scratch.

map global normal <a-X> K<a-x>

additionaly, opposite command can be acheived:

define-command -hidden \
    -docstring "alt-x: wrapper around alt x" \
    alt-x %{ evaluate-commands %sh{
        if [ $(printf "%s" "${kak_selection}" | wc -m) -eq 1 ]; then
            printf "%s\n" "execute-keys <a-x>"
        else
            printf "%s\n" "execute-keys J<a-x>"
        fi
    }}

mapping this function to alt x will keep default altx behavior for single character selections, and will select next line otherwise

My common case is that I don’t want to correct a movement if that’s possible…

Yeah, wonderful. Only thing is it won’t select the next line down on a second hit of <a-x>, but in other cases works as I’d like it to work.

Although I find it a little bit disturbing to call some shell commands for a normal mode keystroke, it seems not to lag.

For me if I press <a-x> first time it selects the line, if I press <a-x> second time it selects next line.

I think the code should be adjusted though:

define-command -hidden \
-docstring "alt-x: wrapper around alt x" \
alt-x %{
    try %{
        execute-keys "<a-k>.\n<ret>"
        execute-keys "J<a-x>"
    } catch %{
        execute-keys "<a-x>"
    }
}

This variant doesn’t use shell, and is more like plain <a-x>

How to make x select lines downward and X select lines upward?

1 Like

Sorry, I ment it doesn’t select the next line on a second hit when on an empty line.

Ah, that’s default <a-x> behavior, and it would be a bit harder to workaround this, see: https://github.com/mawww/kakoune/issues/2590

Ah, yes, totally agree with that.

Try the following mappings in your kakrc

For 1:

use

map global normal <a-r> ';r'

only r is actually mapped to anything so tonnes of room to change the bindings there.

Edit - Nevermind, R and <a-R> are both mapped to something but <a-r> is still free

For 2:

map global normal f      ';F'
map global normal <a-f>  ';<a-F>'
map global normal .      ';<a-.>'

only downside of this mapping is that it slightly changes the behaviour for when you reach the last f.
you also need to rebind the normal .

But this lets you press . to repeat the last action as per normal but <a-.> will always force selection.
This doesn’t work for T because you have to move past the character to do the next T. I have a mapping for that I can post but it’s kinda complicated and I never use T anyway.

For 3:

already answered

For 4:

AFAIK X4Jc is identical to 5cc in Vim. A lot more keys tho. But I’m already holding down Shift so it’s not a big deal to press <shift+x> then just hammer j while still holding shift.
If you want to go up press <shift+k> but if you reach the original line then you want to go <a-;> before press <shift+k> or, as other posters said, you don’t get the whole line.

3 Likes

This may not be his common case, but it is mine! Is there a more efficient way possible?

If this is a common case for you @alex.boswell – I would recommend a custom binding for it. I have a lot of custom bindings just for stuff I happen to use a lot that shouldn’t be generalized.

1 Like