在NvChad Nvim中覆盖默认设置。

6
我希望将NvChad望远镜插件的layout_strategy从默认值horizontal更改为vertical。这可以通过设置layout_strategy = "vertical"来实现。在某个地方... 根据NvChad文档,我可以在自己的custom/init.lua中覆盖plugins/configs/telescope.lua中指定的默认设置,但我也发现可以/应该在custom/chadrc.lua中完成。
问题是:我需要在哪个文件中添加哪些行以更改望远镜插件的默认layout_strategy,并保留其他默认设置不变? 我已经尝试添加到custom/chadrc.lua
M.telescope = {
  layout_strategy = "vertical"
}

也尝试过

M.telescope = {
  defaults = {
      layout_strategy = "vertical",
    },
  }
}

并且

local o = vim.telescope.defaults
o.layout_strategy = "vertical"

但似乎不起作用。
2个回答

6
在你的chadrc.lua文件中,你可以这样覆盖选项:
M.plugins = {
    -- ...
    ["nvim-telescope/telescope.nvim"] = {
        override_options = function()
            return {
                defaults = {
                    layout_strategy = "vertical",
                    layout_config = {
                        height = 0.95,
                        prompt_position = "top",
                        vertical = {
                            mirror = true,
                            preview_cutoff = 0,
                        },
                    },
                },
            }
        end,
    },
    -- ...
}

如果您希望在底部有预览部分,我已将我的附加layout_config包含在内。此外,对于我来说,preview_cutoff是必需的,否则预览永远不会出现。

基本上,override_options返回的表格将强制扩展NvChad提供的默认配置,并将结果表格传递到插件的setup函数中。

定义override_options是处理NvChad预安装插件的方法。如果您正在处理新的自定义插件,则需要在插件声明的config函数中自行调用插件的setup函数:

M.plugins = {
    -- ...
    ["any-vendor/any-custom-plugin.nvim"] = {
        config = function()
            require('custom-plugin').setup({
                -- ...
            })
        end,
    },
    -- ...
}

这与 telescope.nvim 无关,因为它是预装的,但我仍想完整地解释一下。


3
从NvChad 2.0版本开始,插件管理使用lazy.nvim,因此语法略有变化。
-- custom/plugins.lua
-- ...
  {
    "nvim-telescope/telescope.nvim",
    opts = {
      defaults = {
          layout_strategy = "vertical",
          layout_config = {
              height = 0.95,
              prompt_position = "top",
              vertical = {
                  mirror = true,
                  preview_cutoff = 0,
              },
          },
      },
    },
  },
-- ...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接