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

Use motions for delete and change #102

Closed svenXY closed 2 years ago

svenXY commented 2 years ago

Checklist

Describe the solution you'd like I have a quote over a few lines and want to remove the quotation marks. Neither dsap" or - in my case - dsG" work.

Also, there is no possibility to make a visual selection and the delete based on the selection, which would also satisfy my usecase.

kylechui commented 2 years ago

If you check out the wiki, you'll find that ds and cs don't take text-objects as "arguments". I think the idea of deletions via visual selections isn't something that I'll add, since you can probably just delete them manually if you're already taking the time to visually select it. It would also introduce a whole host of issues like:

This isn't to say that I'm completely disinterested in this enhancement; I'm curious to understand which circumstances you find yourself in where a quote spanning several lines happens. There are a few things to consider when implementing this, including

I'm currently thinking through #101, to see if there's a way I can implement "more custom" modifications to surrounding pairs that doesn't involve relying on Vim's built-in text-objects.

svenXY commented 2 years ago

hI, sorry for answering late.... To be quite honest, the usecase occurred to me when I copy-pasted something with mutliple lines and it had quotes around it. I tried the usual, read the documentation and realized that many motions are not possible for cs and ds - and that was when I came up with the solution.

But I agree that it is not a veeeeery common case and that many questions woud have to be answered first, so I'm fine to close this.

Thanks for thinking about it!

Cheers, Sven

kylechui commented 2 years ago

@svenXY On the new branch pattern-matching (see #101) there is a way to have ds" delete quotes across lines by default (or some other key), but it comes at the cost of probably not being nearly as accurate with detecting what constitute "valid strings". I'll look into it a bit more.

kylechui commented 2 years ago

If you're interested, the related configuration is

['"'] = {
    add = function()
        return { { '"' }, { '"' } }
    end,
    find = '".-"',
    delete = '^(")().-(")()$',
    change = {
        target = '^(")().-(")()$',
    },
},

in the delimiters table, although I would read through the most recent messages I've sent in #101, since there are a lot of changes to how user configuration works.