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

Remove whitespace with ( #122

Closed petobens closed 2 years ago

petobens commented 2 years ago

Hi if I have a something like: [foo] and I press cs[( then I get [ foo ]. I would like open parenthesis to avoid adding the leading/trailing whitespace (i.e basically swap the default behaviour of ( for ))? Is that possible? I had something working prior to todays changes with:

require('nvim-surround').setup({
    delimiters = {
        pairs = {
            ['('] = { '(', ')' },
        },
}})

but that is not working anymore.. Thanks in advance!

kylechui commented 2 years ago

See the breaking changes issue (#77), many changes have been made to configuration that break things. You're going to want to put the table under the add key.

petobens commented 2 years ago

Hi! I indeed saw that but if I add:

require('nvim-surround').setup({
    surrounds = {
        ['('] = {
            add = { '(', ')' },
        },
    },
})

and then for instance try ds( on (foo) it won't work since I probably also need to add a delete entry to the surrounds table.. My question therefore is: is there an easy way to simple map/swap ( to have the same of ) for add, delete and change?

kylechui commented 2 years ago

You can set the ( surround to false, then alias ( to ) in the aliases table. See the default configuration for examples.

Edit: @petobens I was away from my computer earlier, but here's a config you can try:

require("nvim-surround").setup({
    surrounds = {
        ["("] = false,
    },
    aliases = {
        ["("] = ")",
    },
})
kylechui commented 2 years ago

Hi! I indeed saw that but if I add:

require('nvim-surround').setup({
    surrounds = {
        ['('] = {
            add = { '(', ')' },
        },
    },
})

and then for instance try ds( on (foo) it won't work since I probably also need to add a delete entry to the surrounds table.. My question therefore is: is there an easy way to simple map/swap ( to have the same of ) for add, delete and change?

Also with respect to why your original setup didn't work: you are correct that you would need to provide find/delete keys; they were defaulting to the invalid_key_behavior behavior, and was trying to delete { '(', '(' } pairs.

petobens commented 2 years ago

Thanks!

kohane27 commented 1 year ago

just want to leave a comment for OP: I had the exact same issue. And of course, thank you kylechui for providing the exact solution we need!