better-escape.nvim icon indicating copy to clipboard operation
better-escape.nvim copied to clipboard

feat: allow more than 2 keys

Open Sam-programs opened this issue 8 months ago • 16 comments

fixes #106 Because you can make the preceded characters and set them to "" to disable the plugin:

v = {
    j = {
        j = {
            k = "",
        },
    }
},

This example fixes https://github.com/max397574/better-escape.nvim/issues/106#issuecomment-2607330551

Sam-programs avatar Mar 28 '25 02:03 Sam-programs

It's a draft because I am not sure if there are any bugs. It seems to work fine though. Also because the commits are a mess.

Sam-programs avatar Mar 28 '25 02:03 Sam-programs

@max397574 What the point of unmap_keys (formally clear_mappings) ? vim.keymap.set already overwrites old mappings.

Never mind it clears the mappings when setup() is called 2 times.

Sam-programs avatar Mar 28 '25 05:03 Sam-programs

👀

busy this weekend, will look into it next week

max397574 avatar Mar 28 '25 06:03 max397574

I should probably add some readme examples for this. I was waiting for #112 to be merged.

Sam-programs avatar Mar 31 '25 18:03 Sam-programs

turned out I was busy for more than one week 😅

Code looks good to me I'll tests this myself locally for a few days before merging it (I guess you already have used this for some time yourself?)

max397574 avatar Apr 22 '25 15:04 max397574

(I guess you already have used this for some time yourself?)

No, I actually haven't been coding that much for the last few weeks because of school, but I did test the code a bit.

Sam-programs avatar Apr 22 '25 15:04 Sam-programs

When I use jk to esc (with mappings from default config) the cursor moves up a line when on an empty line

not 100% sure yet what in the code causes this regression

max397574 avatar Apr 29 '25 09:04 max397574

Uh, It also deletes the previous character on non empty lines. Found a fix though.

Sam-programs avatar Apr 29 '25 12:04 Sam-programs

Nvm the fix breaks if a key has multiple parents.

Sam-programs avatar Apr 29 '25 12:04 Sam-programs

somehow this also broke with this pr

    i = {
        [" "] = {
            ["<TAB>"] = function()
                vim.defer_fn(function()
                    vim.o.ul = vim.o.ul
                    require("luasnip").expand()
                end, 1)
            end,
        },
    },
},

max397574 avatar Apr 29 '25 12:04 max397574

How did it break ? What happens ?

Sam-programs avatar Apr 29 '25 12:04 Sam-programs

Oh the plugin maps " <Tab" as parents for the sequence " <Tab>".

Sam-programs avatar Apr 29 '25 12:04 Sam-programs

We could fix it by simply removing the multiple keys layout(https://github.com/max397574/better-escape.nvim/pull/113/commits/13306ef3f62f523fb6adb91ad676b6c7495797a8) or dirty fix it by translating the key to escape codes then checking if the string changes. If https://github.com/neovim/neovim/issues/26575 were fixed, it could allow us to just parse the keys.

Sam-programs avatar Apr 29 '25 12:04 Sam-programs

Both issues should be fixed now. But there's still a bug where the plugin overdeletes if you map multiple special characters:

i = {
    ["<Tab>"] = {
        ["<Tab>"] = "<Esc>",
    },
},

I don't think it's relevant enough to fix.

Sam-programs avatar Apr 30 '25 00:04 Sam-programs

perhaps we should just mention this somewhere in the readme that it's a known limitation

max397574 avatar Apr 30 '25 06:04 max397574

perhaps we should just mention this somewhere in the readme

I was gonna do that. I wanted to discuss it first in case you had a solution or if there was a use case for special characters that we could hardcode.

Also I misunderstood the issue: the bug only happens if the special key is not the final key in a mapping, heres a better example:

i = {
    ["<Tab>"] = {
         j = "<Esc>",
    },
},

Sam-programs avatar Apr 30 '25 16:04 Sam-programs