nvim-surround icon indicating copy to clipboard operation
nvim-surround copied to clipboard

Toggle quotes (`ts`)

Open kylechui opened this issue 2 years ago • 13 comments

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 avatar Jul 20 '22 00:07 kylechui

@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?

kylechui avatar Jul 20 '22 01:07 kylechui

I too would love to have this feature.

devkvlt avatar Jul 21 '22 15:07 devkvlt

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

kylechui avatar Jul 22 '22 00:07 kylechui

@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

voyeg3r avatar Jul 26 '22 01:07 voyeg3r

@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 = { "'", '"', "`" },
}

kylechui avatar Jul 26 '22 01:07 kylechui

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!

pearofducks avatar Jul 27 '22 17:07 pearofducks

@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

kylechui avatar Jul 27 '22 17:07 kylechui

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

pearofducks avatar Jul 27 '22 18:07 pearofducks

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!

kylechui avatar Jul 27 '22 18:07 kylechui

@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

voyeg3r avatar Aug 03 '22 12:08 voyeg3r

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 avatar Aug 13 '22 04:08 kylechui