在 Neovim + Lazy.nvim 中,除了第一个映射外,插件的键映射不起作用。

huangapple go评论81阅读模式
英文:

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

问题

我正在使用 Neovim 版本 0.9,并使用 Lazy.nvim 包管理器。使用以下配置,安装了 nvim-telescope。我设置了两个映射:<leader>ff<leader>fg。只有第一个有效;在这种情况下是 live_grep。根据 Lazy.nvim 的规范(https://github.com/folke/lazy.nvim#-plugin-spec),keys 接受一个数组。

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

这个配置有什么错误?我希望保留键绑定与插件配置一起,以便将与插件相关的完整配置保存在单个文件中。

英文:

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; &lt;leader&gt;ff && &lt;leader&gt;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 {
  { &#39;nvim-telescope/telescope.nvim&#39;, 
    tag = &#39;0.1.1&#39;,
    dependencies = { &#39;nvim-lua/plenary.nvim&#39; },
    keys = {
      {
        {&#39;&lt;leader&gt;fg&#39;, &quot;&lt;cmd&gt;Telescope live_grep&lt;cr&gt;&quot;, desc = &quot;Live grep&quot;},
        {&#39;&lt;leader&gt;ff&#39;, &quot;&lt;cmd&gt;Telescope find_files&lt;cr&gt;&quot; desc = &quot;Find file&quot;},
      },
    },    
  }
}

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.

答案1

得分: 1

Syntax error, you are not passing an array. You 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"},
    },
  },
}
英文:

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

return 
{
  { 
    &#39;nvim-telescope/telescope.nvim&#39;, 
    tag = &#39;0.1.1&#39;,
    dependencies = { &#39;nvim-lua/plenary.nvim&#39; },
    keys =
    {
      {&#39;&lt;leader&gt;fg&#39;, &quot;&lt;cmd&gt;Telescope live_grep&lt;cr&gt;&quot;, desc = &quot;Live grep&quot;},
      {&#39;&lt;leader&gt;ff&#39;, &quot;&lt;cmd&gt;Telescope find_files&lt;cr&gt;&quot; desc = &quot;Find file&quot;},
    },
  },
}

huangapple
  • 本文由 发表于 2023年6月26日 14:24:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554011.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定