machakann / vim-sandwich

Set of operators and textobjects to search/select/edit sandwiched texts.
1.44k stars 37 forks source link

The last character of previosly changed text mark `] is off by 1 #155

Closed EgZvor closed 2 years ago

EgZvor commented 2 years ago

I've been experimenting with the last changed text text object

xnoremap . `[o`]
onoremap . <cmd>normal v.<cr>

and found the following behaviour unintuitive (pipes signify the cursor)

Hello, wo|r|ld, it's me
saiw"
Hello, "|w|orld", it's me
0 -- move away
|H|ello, "world", it's me
`[ -- as expected
Hello, |"|world", it's me

'] -- **after** the quote
Hello, "world"|,| it's me

-- expected
Hello, "world|"|, it's me

Can this be fixed?

machakann commented 2 years ago

This is intended. For example, put the line on a buffer.

ad

and then insert bc in between a and d.

abcd

Now, if you type 0`[, the cursor will be moved onto b. On the other hand, if you type 0`], the cursor will be on d, not c. Vim-sandwich just follows the rule of how vim behaves when a string is inserted.

I usually think the marks are in between two characters rather than on a character, and the cursor comes to the right side of the mark always.

1 2 3 4 5
 a b c d

If bc is inserted, the range surrounding the inserted text is from 2 to 4. Therefore, 0`] moves the cursor right after the 4.

EgZvor commented 2 years ago

That's what I suspected. I tried modifying the text object like this

xnoremap . `[o`]h
onoremap . <cmd>normal v.<cr>

but then the motion like gu isn't registering correctly.

I think I'll create a thread in vim-dev group about this.