Search code examples
neovimtelescope.nvim

Override default settings in NvChad Nvim


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.


Solution

  • 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.