kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
3.16k stars 63 forks source link

Surround favors jumping to pair instead of selecting surrounding pair #166

Closed zdcthomas closed 1 year ago

zdcthomas commented 1 year ago

Checklist

To reproduce

In the buffer

  path = 'foo('CURSOR_HERE')'

and the minimal setup

use({
    "kylechui/nvim-surround",
    tag = "*", -- Use for stability; omit to use `main` branch for the latest features
    config = function()
        require("nvim-surround").setup({
            -- Configuration here, or leave empty to use defaults
        })
    end
})

Expected behavior

I would expect surround to target the pair of ' actually surrounding the cursor.

Based on the jumps section of the docs I would expect the opposite of this behavior.

Actual behavior

The cursor jumps to the final pair of ' and deletes/changes them. I.E

keystrokes: ds' buffer:

path = 'foo('CURSOR_HERE)

Additional context

Thanks for the awesome plugin! super appreciate all the hard work!

I'd be super down to try to contribute a solution also, if someone could point me to roughly where to look!

kylechui commented 1 year ago

See #153, as this is probably the exact same situation; I am now strongly preferring to revert the code.

zdcthomas commented 1 year ago

Ahh, sorry I didn't catch that, yeah it looks identical. I could look into making it an option and by default preferring the standard, more predictable way?

Personally I've never been a big fan of jump ahead behaviors, so I might be biased.

kylechui commented 1 year ago

I don't fully remember if I've commented my code properly, but the relevant portions are probably in motions.lua, in particular wherever the is_quote function is called. It's basically used to "jump ahead" whenever the character is a quote. However, it doesn't lend itself very well to extensibility (in particular, by the user) and is somewhat "hard-coded" in at the moment. I was originally thinking of just omitting the code altogether since it seems to be more confusing for people as a whole, and is an extra burden to maintain. If you're able to find some aesthetically pleasing way to abstract the functionality however, I'm all ears.

More complications: If the user decides to define a new surrounding pair that is different from the "trigger" character, then the process of moving the cursor to the beginning is non-trivial.

zdcthomas commented 1 year ago

Ahh good point on that, that's definitely an extra level of complication.

zdcthomas commented 1 year ago

Then yeah, I think I totally agree about taking it out. Ultimately it'll make things more predictable which I think is worth it

kylechui commented 1 year ago

Closing this to centralize discussion in #153