kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
3.18k stars 62 forks source link

Incorrect behavior at end of buffer / empty line #87

Closed smjonas closed 2 years ago

smjonas commented 2 years ago

Checklist

To Reproduce First of all, sorry for bombarding you with all these issues :smile:

  1. Paste these two lines in a buffer:
    
    }
2. Move to the second line.
3. `ysiwX`
4. Observe how the buffer contents changed to

x} x



**Expected behavior**
The buffer contents should not have changed.

**Additional context**
I think an empty line should not be treated as a word in general (try `ysiwX` on an empty line that is not at the end of a buffer).
kylechui commented 2 years ago

So you're saying that if ysiw is triggered on an empty line, then an effective NOOP should be done? I will say that this might be something that I don't "fix", given that vim-surround does not handle this "edge case" either, and iw as a text-object selects the newline character (e.g. try viw on an empty line). I think the reasoning for this is that "empty" lines are actually lines with just the newline character, which yields behavior different than what you are suggesting.

smjonas commented 2 years ago

Ok, I think it's ok to close this then as this seems like an unusual edgecase (btw, vim-sandwich behaves exactly the same too).

kylechui commented 2 years ago

Thanks for bringing it up to begin with though! I really appreciate the feedback/possible improvements