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

Improved `count` support

Open mawkler opened this issue 3 years ago • 4 comments

Checklist

  • [x] Have you read through :h nvim-surround to see if there might be any relevant information there?

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.

mawkler avatar Aug 29 '22 10:08 mawkler

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).

smjonas avatar Aug 29 '22 12:08 smjonas

@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 avatar Aug 29 '22 21:08 kylechui

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:

  • Parse numbers myself to see how many times to repeat a given action (seems relatively easy IMO)
  • Force a breaking change where numbers are no longer valid surround keys (a bigger deal)

kylechui avatar Mar 15 '23 19:03 kylechui

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 avatar Aug 30 '23 04:08 kylechui

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 avatar May 30 '24 19:05 kylechui

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.

kylechui avatar Jun 07 '24 01:06 kylechui