justinmk / vim-sneak

The missing motion for Vim :athletic_shoe:
http://www.vim.org/scripts/script.php?script_id=4809
MIT License
3.26k stars 88 forks source link

Pressing `C` to jump to a label deletes text to the end of the line #273

Closed knpwrs closed 3 years ago

knpwrs commented 3 years ago

Consider the following file contents:

Something Cosomething Casomething Cosomething
Something Casomething Cosomething Cosomething
Something Cosomething Casomething Cosomething
Something Cosomething Casomething Cosomething

I have sneak mapped to z. With my caret at the first character on the first line, pressing zCo highlights the first C with a label C. Pressing C (capital C) jumps the caret to that location and the rest of the line gets deleted:

Something 
Something Casomething Cosomething Cosomething
Something Cosomething Casomething Cosomething
Something Cosomething Casomething Cosomething

Pressing another label (such as ;) just jumps to that location with no issues.

See this asciinema recording: https://asciinema.org/a/409297

ggandor commented 3 years ago

If I understand the implementation correctly, this is actually the intended behavior. The cursor always jumps to the first match automatically, and it is not labeled like the rest; the C you see is the character under the cursor itself. The magenta background is a temporary highlight for the cursor. (Sneak still waits for input - getchar() is executing under the hood -, and the cursor would be hidden otherwise, so this little hack is necessary.) One thing that is curious though is that the cursor highlight should be black or white by default - it uses the SneakScope group, the same that is used for highlighting the vertical scope (:h sneak-vertical-scope). I don't know why it is overridden by the SneakLabelMask properties (if that is what happens). Is the vertical scope highlighted in your machine with magenta too?

Once the cursor has jumped to the first match, and the labels appeared, pressing esc or g:sneak#opt.label_esc - by default, space - accepts the first match, and you exit label-mode. Pressing any other key that is not on the target label list (g:sneak#target_labels) accepts the first match and exits label-mode too, but the keypress is passed on to Vim, so the deletion happens because C will be interpreted as a Normal mode command by then.

knpwrs commented 3 years ago

That makes sense. Thank you, @ggandor!