Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to delete a surround similar to how we can add a surround(re: textobjects) #347

Open
1 task done
pejrich opened this issue Aug 5, 2024 · 4 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@pejrich
Copy link

pejrich commented Aug 5, 2024

Checklist

  • 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.
If I have a buffer like this:

("here_are_|some_words")

I can do ysa"_ to give me:

(_"here_are_|some_words"_)

if I want to delete a surround ds_, I get:

(_"here_are|somewords"_)

What would be awesome is if I could delete similar to how I can add. So something like dsa"_([D]elete [S]urround [A]round ["]quote [_]undescore`

("here_are_|some_words")

I understand that these keymaps are a bit unvim-like, and would conflict with the existing ones(i.e. dsa"_ would trigger dsa which would delete the closest surrounding a), so maybe an alternative, more vim-like approach, would be to have this only work in visual mode. So it would be more like va"D_(D being an example key for triggered surround delete in visual mode). Then it would work just like the existing delete functionality, except instead of finding the closest surround to the cursor, it finds the closest surround to the edges of the visual selection.

Additional context
I did take a look at the existing code to see if I could easily implement it with existing functions, but it seemed like the current delete functionality is all cursor/single position based. I would be happy to take a stab at it, but wanted to check first if this was something you'd be interested in adding to the plugin or not, or if you had any suggestions on the best way to implement it.

Thanks! And I appreciate all your work on this plugin. It's one of my most used, if the not the most used plugin for me.

EDIT: I changed the (spaces) to _ underscore to make it more clear.

@pejrich pejrich added the enhancement New feature or request label Aug 5, 2024
@kylechui
Copy link
Owner

kylechui commented Aug 6, 2024

At the moment, I don't have any plans to implement such a feature. If this is particular case is something that happens often, one could create their own surround that specifically handles this _"..."_ case. Additionally, I'm largely opposed to it because of the breaking change that it would cause (setup function incompatibility).

@pejrich
Copy link
Author

pejrich commented Aug 7, 2024

@kylechui Why would there be a breaking change? Since it would be an additional, opt-in, visual mode-only binding. I'm also a bit unsure how I would go about creating a surround that would handle this. If I want to remove the spaces between a given element ( { " word " } ), say I want ({ " word " }), my proposal is that va}D would remove that space. Likewise va)D would give ({ " word " }). To my knowledge there's no way to currently do this.

But point taken if it's not something you think fits the plugin.

@bew
Copy link
Contributor

bew commented Aug 7, 2024

On the topic of breaking changes, it could be a new Lua API only, without default keybind 🤔

@kylechui
Copy link
Owner

kylechui commented Aug 7, 2024

Ah I see, I accidentally missed the part where you suggested using a visual binding and not just using ds... in normal mode. I'm not totally opposed to the idea, but at the moment it doesn't seem like a basic change to the codebase either. My best guess is that the get_best_selection function (or whatever I called it) would need to be updated to take a range (i.e. a selection) as input, and all existing function calls would pass in a selection with first_pos = last_pos = curpos or something. Definitely not the easiest thing to get right I imagine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants