neovim

In Neovim + Lazy.nvim, keymapping for a plugin does not work except for the first mapping


I am using Neovim version 0.9 with Lazy.nvim package manager. Using the below configuration, nvim-telescope gets installed. I have set two mappings; <leader>ff && <leader>fg. Only the first one works; live_grep in this case. By Lazy.nvim specification in https://github.com/folke/lazy.nvim#-plugin-spec, keys accepts an array.

return {
  { 'nvim-telescope/telescope.nvim', 
    tag = '0.1.1',
    dependencies = { 'nvim-lua/plenary.nvim' },
    keys = {
      {
        {'<leader>fg', "<cmd>Telescope live_grep<cr>", desc = "Live grep"},
        {'<leader>ff', "<cmd>Telescope find_files<cr>" desc = "Find file"},
      },
    },    
  }
}

What is the mistake with this configuration? I would prefer to retain the keybinding along side the plugin configuration to keep the complete configuration related to a plugin in a single file.


Solution

  • Syntax error, you are not passing an array. Your are passing a nested array. you need to pass:

    return 
    {
      { 
        'nvim-telescope/telescope.nvim', 
        tag = '0.1.1',
        dependencies = { 'nvim-lua/plenary.nvim' },
        keys =
        {
          {'<leader>fg', "<cmd>Telescope live_grep<cr>", desc = "Live grep"},
          {'<leader>ff', "<cmd>Telescope find_files<cr>", desc = "Find file"},
        },
      },
    }