kylechui / nvim-surround

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

Wrong match when using s as a trigger key #235

Closed maxigaz closed 1 year ago

maxigaz commented 1 year ago

Checklist

Neovim Version

v0.8.3

Plugin Version

Tagged (Stable)

Minimal Configuration

vim.cmd([[let $PLUGIN_DIRECTORY = '~/.local/share/nvim/plugtest']])
vim.cmd([[packadd nvim-surround]])

require("nvim-surround").setup({
  surrounds = {
    -- strong emphasis for markdown
    ["s"] = {
      add = { "**", "**" },
      find = "%*%*.-%*%*",
      delete = "^(%*%*?)().-(%*%*?)()$",
      change = {
        target = "^(%*%*?)().-(%*%*?)()$",
      },
    },
  },
})

Sample Buffer

This is a test sentence with **emphasis**.

Another one (for good measure).

Keystroke Sequence

dss

Expected behavior

When the cursor is on **emphasis**, pressing the keystroke above deletes the surrounding asterisks, leaving emphasis. as a result.

Actual behavior

The parentheses in the second paragraph are deleted, leaving Another one for good measure. as a result.

Additional context

I adapted the example in this comment, where I changed the trigger key from * to s.

If I change it back to * or replace it with another letter such as e, it works without any issues.

kylechui commented 1 year ago

Have you tried setting the alias s to false in the setup function? By default, s is an alias that matches "any built-in surround".

maxigaz commented 1 year ago

I've only tried that just now. It solves the problem. Thank you!