how to make config
and opts
coexist in a plugin's setting file, if they can?
#1248
-
I have the following config for However, only the settings in the May I ask if these two sections can coexist? If not, how do I merge one to the other? Thanks. return {
{
'nvim-telescope/telescope.nvim',
tag = '0.1.5',
dependencies = {
'nvim-lua/plenary.nvim',
},
config = function ()
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
end,
opts = {
-- change some default options
defaults = {
layout_strategy = "horizontal",
layout_config = {
prompt_position = "top",
-- preview_width = 100, -- fix width of preview window
},
sorting_strategy = "ascending",
winblend = 0,
},
pickers = {
find_files = { hidden = true }, -- show hidden files in search
},
},
},
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
That's because when you define a config = function(_, opts)
require("telescope").setup(opts)
-- rest of your code goes here
end It would also be beneficial to you if you took advantage of the |
Beta Was this translation helpful? Give feedback.
-
Thank you, @dpetka2001 for the detailed explanation. I've revised my config file according to your suggestion with comments: return {
{
'nvim-telescope/telescope.nvim',
tag = '0.1.5',
dependencies = {
'nvim-lua/plenary.nvim',
},
-- keymaps can also be defined in the config func using vim.keymap.set()
keys = {
{
'<leader>ff',
'<cmd>Telescope find_files<cr>',
desc = 'find files',
},
{
'<leader>fg',
'<cmd>Telescope live_grep<cr>',
desc = 'live grep',
},
-- {
-- '<leader>fb',
-- '<cmd>Telescope buffers<cr>',
-- desc = 'find buffers',
-- },
},
-- the 'opts' table as defined here can be passed as an arg of the config func
opts = {
-- change some default options
defaults = {
layout_strategy = "horizontal",
layout_config = {
prompt_position = "top",
-- preview_width = 100, -- fix width of preview window
},
sorting_strategy = "ascending",
winblend = 0,
},
pickers = {
find_files = { hidden = true }, -- show hidden files in search
},
},
config = function (_, opts)
require('telescope').setup(opts)
-- keymap can also be defined in the 'keys' section as shown above
local builtin = require('telescope.builtin')
-- vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
-- vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
end,
},
{
'nvim-telescope/telescope-ui-select.nvim',
config = function ()
require("telescope").setup({
extensions = {
["ui-select"] = {
require("telescope.themes").get_dropdown {
-- even more opts
}
}
}
})
require("telescope").load_extension("ui-select")
end,
},
} |
Beta Was this translation helpful? Give feedback.
That's because when you define a
config
function in your personal configuration, you're overwriting the default implementation thatlazy.nvim
uses. In that case, the user is responsible for calling thesetup
for the plugin and passingopts
into it. Something like the following would be needed specifically for theconfig
function to also take into account theopts
It would also be beneficial to you if you took advantage of the
keys
section for the plugin spec to define the keymaps that you want instead of defining them in theconfig
function (this way you also ensure that the plugin will be l…