kylechui / nvim-surround

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

Toggle quotes (`ts`) #98

Open kylechui opened 2 years ago

kylechui commented 2 years ago

On behalf of #79, add a new keymap for toggling quotes, perhaps ytq for "you toggle quotes" tsq for "toggle surrounding quotes. For example in the buffer:

local str = "This seems to be my default example"

Hitting tsq.. will toggle the double quotes "'`". The exact order can probably be determined via some config option in the setup table. Perhaps use aliases or a new section titled cycles or something. While the aliases table could be used, it makes some sense to keep it separate, so dsb could be preserved for deleting parentheses, while opening up tsb for toggling the nearest bracket: ), }, ], >. Open to suggestions from the community on how they would like the interface to look!

I could also just change it so aliases are used and p refers to any pair of those brackets, instead of "overloading" the use of b that much.

kylechui commented 2 years ago

@voyeg3r Seeing as you were the one requesting the feature, perhaps you can give a bit more information/a more concrete description of what you would like to see out of this feature?

devkvlt commented 2 years ago

I too would love to have this feature.

kylechui commented 2 years ago

@devkvlt Thanks for the input; it will probably be the next "big" feature I add after pattern-based modifications in #101

voyeg3r commented 2 years ago

@voyeg3r Seeing as you were the one requesting the feature, perhaps you can give a bit more information/a more concrete description of what you would like to see out of this feature?

I think you have captured the gist of the idea, hit a key combination to quickly change double quotes to single quotes and/or crasis

kylechui commented 2 years ago

@voyeg3r Do you think it would be a bad idea to "tie" this feature together with aliases? For example, you would be able to have tsp for braces, but that would force dsp to delete all sorts of braces as well.

On second consideration it's probably a bad idea to "mix" the two features together; it's probably better to add a new key toggle into the setup table, e.g.

toggle = {
    q = { "'", '"', "`" },
}
pearofducks commented 2 years ago

Just wanted to throw in that my intuitive guess at how this feature worked would have been that csqq would have done what the original message is suggesting tsq does.

csqb changes quotes to brackets, so it feels somewhat "natural" to me that csqq would change the quotes to another quote-type.

Regardless, thanks for the work done on this awesome plugin!

kylechui commented 2 years ago

@pearofducks Thanks for the kind words :) As for csqq, I think this could work as a feature but I think it would be relatively limited in scope, at least for me. The example I cited earlier was that I would like tsb to toggle between () and {}, but also dsb to delete parentheses (I'm a bit weird), which wouldn't be possible with your suggestion. Also I think that ts as a keymap prefix just makes more sense, as it follows the cs/ds scheme.

Edit: csqq would also force me to introduce a "special" case for the cs operator, since it would have to discern whether or not del_char and ins_char are the same

pearofducks commented 2 years ago

Totally makes sense, just throwing that out there in case it made things easier instead of harder! :)

kylechui commented 2 years ago

Yeah, the basic idea is that ysiwq doesn't exist, because q is ambiguous when it comes to which delimiter pair to add to the buffer. For that reason, cs)q or csqq wouldn't be "well-defined behavior" as well. Thanks for the suggestion though!

voyeg3r commented 2 years ago

@voyeg3r Do you think it would be a bad idea to "tie" this feature together with aliases? For example, you would be able to have tsp for braces, but that would force dsp to delete all sorts of braces as well.

On second consideration it's probably a bad idea to "mix" the two features together; it's probably better to add a new key toggle into the setup table, e.g.

toggle = {
    q = { "'", '"', "`" },
}

I think having a separated table for toggling quotes is better

kylechui commented 2 years ago

Pushing this back a bit since I made a handful of breaking changes here and there for v2.0.0, and I would like people to really test what exists first before I add any new features.

kylechui commented 5 months ago

Are people still interested in this? Sorry for pushing it back so much :sob:

gaoqiangks commented 1 month ago

Love this feature. But I think this feature is language specific since quotes may be escaped, and escape character may be different in languages.