wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.82k stars 266 forks source link

fix: use escaped mappings for compiled keymaps #989

Closed akinsho closed 2 years ago

akinsho commented 2 years ago

@konart can you please test this branch to see if it fixes your issue

fixes #988

konart commented 2 years ago

@akinsho It does (the mapping actually will toggle nvim-tree). There is however another problem (can't really tell where is the problematic symbol or whatever is).

Here is the error I'm getting if I try to use mapping \[ to open nvim-tree right after nvim startup:

E5107: Error loading lua [string ":lua"]:1: invalid escape sequence near '''

The reason is lazy loading (?) Here is how I load it:

    use({
        "kyazdani42/nvim-tree.lua",
        keys = { "\\[", "\\g" },
        cmd = "NvimTreeFindFileToggle",
        config = function()
            require("settings.nvim-tree")
        end,
    })

So we waiting for either one of two key combinations or the command. With this fix I can run the command and then the mappings work fine. But keys defined in use result in the error mentioned above.

PS: without lazy loading - mappings work as expected.

akinsho commented 2 years ago

@konart thanks for trying this out, can you try again and see if it's resolved now, I've made some changes

konart commented 2 years ago

@akinsho

Okay, keymaps starting with \ now do work. The ones starting with <Leader> do not though.

For example if I load Trouble like this:

    use({
        "folke/trouble.nvim",
        requires = "kyazdani42/nvim-web-devicons",
        config = function()
            require("settings.trouble")
        end,
        module = "telescope",
        cmd = { "TroubleToggle", "TroubleRefresh" },
        keys = { "<Leader>tt" },
    })
akinsho commented 2 years ago

@konart are you sure it's the mapping that isn't working, since unless you have mapped trouble to also open using <leader>tt it will be loaded, but trouble will not open using the setup you have above?

I just tested my localleader and leader mappings, and they seem to work fine.

captainko commented 2 years ago

I believe this PR has bugs, now I cannot lazy load any packages. Please check again.

captainko commented 2 years ago
use({
    "numToStr/Comment.nvim",
    keys = { { "n", "<C-_>" }, { "n", "gcc" }, { "n", "gc" }, { "v", "<C-_>" } },
    config = config("Comment"),
})

this is my config

akinsho commented 2 years ago

Ok I think I give up, I'm going to just revert all the changes

konart commented 2 years ago

@akinsho sorry for the late reply. In my case the problem was with this part: module = "telescope", not with the changes to packer. I guess at some point I just forgot about the changes I've made...

I've tried @captainko keys for Comment too - and at least gcc worked fine for me.

akinsho commented 2 years ago

No worries @konart for now I'm just going to hold off any such changes till when packer is refactored hopefully we won't be doing any more compilation so adding descriptions to lazyload maps will be much easier