Override default settings in NvChad Nvim
Asked Answered
L

2

7

I wish to change the layout_strategy for the telescope plugin from the NvChad default value of horizontal to vertical. This should be possible by setting layout_strategy = "vertical" somewhere...

According to the NvChad docs I can override the default settings specified in plugins/configs/telescope.lua in my own custom/init.lua, but I also found that it could/should be done in the custom/chadrc.lua.

Question

What line(s) do I have to add to what file to change the default layout_strategy for the telescope plugin, and only that (keeping other defaults intact)?

I have tried adding to custom/chadrc.lua

M.telescope = {
  layout_strategy = "vertical"
}

Also tried

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

and

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

But that does not seem to work.

Leucocytosis answered 12/10, 2022 at 19:25 Comment(0)
V
8

In your chadrc.lua you would override options like so:

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

I included my additional layout_config in case you want to have the preview part in the bottom half. Also preview_cutoff was necessary for me or the preview would never show up.

Essentially, the returned table of override_options will forcefully extend the default configs provided by NvChad and the result table would be passed into the setup function of the plugin.

Defining override_options is the way to go for pre-installed plugins of NvChad. If you deal with a new custom plugin, you'd rather need to call the setup function of the plugin on your own in the config function of the plugin declaration like so:

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

This is not relevant for telescope.nvim, since it is pre-installed, but I wanted to address this for completeness anyways.

Velmaveloce answered 8/12, 2022 at 18:11 Comment(0)
L
4

As of NvChad version 2.0 lazy.nvim is used for plugin management, thus slightly changing the syntax.

-- 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,
              },
          },
      },
    },
  },
-- ...
Leucocytosis answered 15/3, 2023 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.