kylechui / nvim-surround

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

Missing surround mappings #202

Closed webshipglenn closed 1 year ago

webshipglenn commented 1 year ago

Checklist

Neovim Version

0.8.2

Plugin Version

Tagged (Stable)

Minimal Configuration

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

Sample Buffer

Any

Keystroke Sequence

cs})

Expected behavior

Change surrounds from " to '

Actual behavior

Nothing happens.

Additional context

I seem to have the same issue as #193, though I'm not sure. Minimal config neovim with just the plugin works great, I can't wait to use it. However, in my current neovim config, it seems nvim-surrounds doesn't generate any mappings at all.

:verbose nmap cs returns "No mapping found"

I suspected whichkey of interfering with surround but disabling it didn't fix the issue. In fact, I've tried pretty much every dumbed-down version of my config to no avail. It really just seems like the key sequence is aborted after pressing the s. ysiw ends up inserting a "w", dsb ends up going back a word...

kylechui commented 1 year ago

Indeed it seems to be that the keymaps aren't being applied to your configuration, as ysiw in default Neovim will try "yanking s" (which is nonsense), so it cancels the yank and just inserts a w at the cursor location. I would say try starting from a minimal configuration with only Neovim and re-enable your other plugins one at a time. I can't really do much with the information that you've provided.

webshipglenn commented 1 year ago

Alright, your comment got me debugging the issue again.

I tried disabling everything about my config, plugins, settings, keymaps... No dice. I then tried to manually load and setup nvim-surround with :lua require('nvim-surround').setup(). That worked. Fiddled around with settings some more but Packer kept refusing to load nvim-surround.

In the end what fixed it for me was creating a surround.lua in after/plugins and loading the plugin there. I usually load plugins that don't require any configuration right in my packer setup as also instructed in your readme, I have no clue why it didn't work for nvim-surround. I probably missed something in the Packer docs.

Sorry to have taken your time over this, I doubt this has anything to do with nvim-surround.

arcturegulus commented 1 year ago

Hi, I wanted to chip in on this just to leave something for people who use lazy.nvim (like me) instead of packer and encountered this same issue. The following was my config for nvim-surround:

{
    "kylechui/nvim-surround",
    event = "VeryLazy",
},

The plugin seemed to load fine (lazy.nvim marked it as loaded and :h nvim-surround.usage works) but like above, no keymaps were set by the plugin ("No mapping found" from :verbose nmap ys).

After some time trying to fix the problem, I tried this:

{
    "kylechui/nvim-surround",
    opts = {}, -- empty opts
    event = "VeryLazy",
},

and now the mappings are there:

image

The problem and fix is the same whether I lazy load the plugin or not.

Other plugins I specify that don't need any configuration work fine without the extra empty opts which leads me to believe it's something to do with nvim-surround itself, but honestly I'm not sure. I really just found this fix by happenstance.