kylechui / nvim-surround

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

Improved `count` support #147

Closed mawkler closed 3 months ago

mawkler commented 2 years ago

Checklist

Is your feature request related to a problem? Please describe.

I think it would be really cool if I for instance could do something like 2siw* to make a word bold in markdown (i.e. convert word into **word**), or do the opposite: 2ds* to make text non-bold in markdown (i.e. convert **word** into word).

Describe the solution you'd like

Prepending a count (i.e. a number 1-9) before a surround command performs the surround that many times over the same text-object.

smjonas commented 2 years ago

I've had the same feature request here: https://github.com/kylechui/nvim-surround/issues/86

There might be some relevant info there :) Btw, I still think this feature is useful (and there's no workaround for your usecase, e.g. ds2* doesn't work).

kylechui commented 2 years ago

@smjonas It seems like this is slightly different; your feature request was about surrounding larger selections (e.g. two words at a time), whereas this seems to be about surrounding a single word twice. @melkster This sounds like a good idea; unfortunately at the moment I need to first get through the other updates (good query support) and some other issues, and then learn how counting works. Apologies in advance if this takes a while, as I'll have less time to work on this during the school year/internship application season.

kylechui commented 1 year ago

Hello! It's been quite a while (sorry), but I'm productively procrastinating on my schoolwork by working on this plugin :smile: Coming back to this issue, it seems that we kind of have two different ways to approach this problem: prefixing the operator or prefixing the surround, i.e. 2ysiw* vs. ysiw2*.

My current thoughts are that the former has no real disadvantages (and can probably be implemented by leveraging the built-in v:count), while the latter would require me to:

kylechui commented 1 year ago

I just realized that there's already a bit of inconsistency with how things work for the yss special case. As of right now, 2yss) would surround two lines with parentheses, instead of surrounding the current line with two sets of parentheses. I'm not exactly sure how to reconcile these differences; if anybody has any ideas feel free to let me know!

Edit: The idea of parsing numbers after the motion is selected seems to make the most sense, e.g. 2yss3) would surround two lines with three sets of parentheses, but would be a breaking change and require me to parse the numbers, as mentioned before.

kylechui commented 3 months ago

Continuing the tradition of replying once a year (sorry!). It seems like I was mistaken before, and that prefixing the motion with a count already applies the count to the motion, i.e. 2ysaw) will surround two words with (...). Thus 2yss) really isn't a "special case", which makes me even less inclined to change the behavior now. The only real option seems to be something like ysiw10), but like I mentioned earlier, I'm not sure if I want to implement the parsing for that...

kylechui commented 3 months ago

I think I'll close this issue for now since implementing this seems to mandate some kind of breaking change, but if anybody has any new ideas that haven't already been posted in this thread, feel free to comment!

Tangentially related is that with the "sticky" option for move_cursor (soon-to-be-merged in #334), one can just dot-repeat the surround to get multiple.