Skip to content

feat: allow more than 2 keys#113

Open
Sam-programs wants to merge 10 commits intomax397574:masterfrom
Sam-programs:multiple_keys
Open

feat: allow more than 2 keys#113
Sam-programs wants to merge 10 commits intomax397574:masterfrom
Sam-programs:multiple_keys

Conversation

@Sam-programs
Copy link
Copy Markdown
Contributor

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

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

This example fixes #106 (comment)

@Sam-programs
Copy link
Copy Markdown
Contributor Author

Sam-programs commented Mar 28, 2025

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
Copy link
Copy Markdown
Contributor Author

Sam-programs commented Mar 28, 2025

@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.

@max397574
Copy link
Copy Markdown
Owner

👀

busy this weekend, will look into it next week

@Sam-programs Sam-programs marked this pull request as ready for review March 28, 2025 20:09
Comment thread lua/better_escape.lua
@Sam-programs
Copy link
Copy Markdown
Contributor Author

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

@Sam-programs Sam-programs force-pushed the multiple_keys branch 2 times, most recently from 4e1815c to 536211c Compare March 31, 2025 18:23
@max397574
Copy link
Copy Markdown
Owner

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?)

@Sam-programs
Copy link
Copy Markdown
Contributor Author

(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.

@max397574
Copy link
Copy Markdown
Owner

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

@Sam-programs
Copy link
Copy Markdown
Contributor Author

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

@Sam-programs
Copy link
Copy Markdown
Contributor Author

Nvm the fix breaks if a key has multiple parents.

@max397574
Copy link
Copy Markdown
Owner

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,
        },
    },
},

@Sam-programs
Copy link
Copy Markdown
Contributor Author

How did it break ? What happens ?

@Sam-programs
Copy link
Copy Markdown
Contributor Author

Sam-programs commented Apr 29, 2025

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

@Sam-programs
Copy link
Copy Markdown
Contributor Author

Sam-programs commented Apr 29, 2025

We could fix it by simply removing the multiple keys layout(13306ef) or dirty fix it by translating the key to escape codes then checking if the string changes.
If neovim/neovim#26575 were fixed, it could allow us to just parse the keys.

jj = false, -- disables both of these:
j = {
    j = "<Esc>",
},
jj = "<Esc>"
@Sam-programs
Copy link
Copy Markdown
Contributor Author

Sam-programs commented Apr 30, 2025

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.

@max397574
Copy link
Copy Markdown
Owner

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

clarify what "special character" means
add the bug into the readme
@Sam-programs
Copy link
Copy Markdown
Contributor Author

Sam-programs commented Apr 30, 2025

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>",
    },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to not escape when preceded by certain characters?

2 participants