Closed ad-chaos closed 1 year ago
If I'm being honest, I don't think this idea is feasible. How would nvim-surround
differentiate between whether the next character is part of a motion, or the actual character to surround with? For example, how would ysa"a
be processed? Is the first a
part of a motion, or signalling to surround with angle brackets?
I also think that since you have already found yourself a workaround for it (just manually setting your maps), it's unnecessary to be implemented in the core plugin. It might be annoying at first but you only really need to set this up once, while I would have to maintain the code necessary to implement this over time. I'm open to hearing any additional thoughts you have about this; if not, then feel free to close this issue.
how would
ysa"a
be processed?
what does do currently? On my machine running the latest head it doesn't do anything, so I am unsure of the intended behaviour.
I am unsure of how nvim-surround handles the ys
operation, does it wait for 2 characters after it and then do its thing? Or is there something else? I think depending on how the semantics are defined it could either be very simple or kinda challenging. Would you mind pointing me to the appropriate files and functions? Maybe I could help :)
ysa"a
should surround the nearest pair of double quotes with angle brackets, i.e. "hello world"
→ <"hello world">
.
Furthermore, as explained in the README, the ys
operator takes in a motion, then a character representing some delimiter pair. The length of the motion is unknown and can be arbitrary, since the user may define their own motions that they wish to use. For example:
ysl)
surrounds the character the cursor is currently sitting on with parenthesesysa])
surrounds the nearest square brackets with parenthesesys14l)
surrounds the next 14 characters with parenthesesNote: All of the above are default motions that one may use; people may decide to use other plugins like
targets.vim
ornvim-treesitter-textobjects
to create more motions likeaf
,il
, etc.
There are no restrictions on what characters may compose a motion, so I think it would be impossible to actually discern if the input characters are part of a motion, or representing a delimiter pair. Relevant files would be init.lua
, in particular normal_surround
and normal_callback
. I would also look into :h opfunc
, if you have not yet already.
Hmm, it is not as simple as I thought indeed. And damn nvim-surround is quite capable, I should explore more into the docs 😅 (Thanks for the plugin!)
Yeah, you're right, this would be too much work for not a huge improvement. I'll close this for now. If I get some ideas I'll let you know 😄
Checklist
:h nvim-surround
to see if there might be any relevant information there?Is your feature request related to a problem? Please describe. Often times I am mostly surround words with quotes, or surround till the end of line with a function or make a parenthetical till the end of a sentence. In such situations I find myself having mappings like
Describe the solution you'd like Now those mappings feel kinda hacky 😅 (and I cannot cover all possible surrounds, like I haven't written down
*
that italicises words in markdown), would be nice if I could specify adefault motion
for them :)This would also make it more consistent with
cs{surround}
andds{surround}
. So, you can justys{surround}
and it'll do the thing that you expect (since you have set a default motion)