kylechui / nvim-surround

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

Add `change_line` mapping #244

Closed srithon closed 1 year ago

srithon commented 1 year ago

Checklist

Is your feature request related to a problem? Please describe. In vim-surround, there's a cS mapping which effectively performs a regular ds surround deletion, followed by a yS on the selection within the deleted surrounding delimiters. Other than this, nvim-surround supports pretty much everything that I used in vim-surround, so I was surprised that it didn't have this feature.

Describe the solution you'd like I would like there to be a change_line mapping which would delete a pair of surrounding delimiters and add a new pair of delimiters on their own lines, surrounding the same region.

Also, in the most common case I would use cS to replace a pair of delimiters with the same pair, except on their own lines. Having another mapping for this would be really nice, as it could (not exactly this since it wouldn't be the default behavior) cut down cS{{ to cS{.

Additional context For example:

if (x > 5) { print <cursor here> "Hello" }

After doing cS{{ (option 1):

if (x > 5)
{
    print "Hello"
}

(option 2):

if (x > 5) {
    print "Hello"
}

I think option 1 would make more sense for consistency with yS, but I also like the option 2 behavior. I believe (I don't remember exactly) that option 2 is the vim-surround behavior, and I think for most use cases it's more useful.

kylechui commented 1 year ago

Hi there, I'm a bit busy right now due to school, but this is something that I would like to implement later. It's been on the TODO list for a while, but I never got around to it (mostly because somehow nobody has asked for it up until this point).

As for your suggestion, I believe that option 2 is both more useful and more consistent, as we are essentially replacing {...} with {\n...\n}, as opposed to option 1, which replaces it with \n{\n...\n}.