我不知道如何用 lua 编写配置。我正在使用 neovim,我的配置是用 lua 编写的。我有几个插件,我使用 lazy nvim 作为我的插件管理器。
我有一个单独的插件目录,其中包含我的插件的 lua 文件。我目前有以下内容作为我的 indent-blankline.lua 文件:
local Plugin = {'lukas-reineke/indent-blankline.nvim'}
Plugin.name = 'indent_blankline'
Plugin.main = 'ibl'
Plugin.event = {'BufReadPost', 'BufNewFile'}
-- See :help ibl.setup()
Plugin.opts = {
enabled = false,
scope = {
enabled = false,
},
indent = {
char = '▏',
},
}
return Plugin
我想添加下面的配置,该配置是我在插件的 github 页面中找到的。它将为线条应用颜色:
local highlight = {
"RainbowRed",
"RainbowYellow",
"RainbowBlue",
"RainbowOrange",
"RainbowGreen",
"RainbowViolet",
"RainbowCyan",
}
local hooks = require "ibl.hooks"
-- create the highlight groups in the highlight setup hook, so they are reset
-- every time the colorscheme changes
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
end)
require("ibl").setup { indent = { highlight = highlight } }
我不确定如何/在哪里放置上述内容。我想知道是否有人可以告诉我如何将其集成到我的配置中。
答案1
对于 lazy.nvim 插件,您需要返回一个包含配置函数的表。在配置函数中,您可以将选项传递给 Indent Blankline 的setup()
函数,以及注册您的钩子。此代码直接返回表,但您也可以构建它然后返回它,就像您上面所做的那样。
-- nvim/lua/plugins/indent-blankline.lua
return {
{
"lukas-reineke/indent-blankline.nvim",
name = "indent_blankline",
event = { "BufReadPost", "BufNewfile" },
config = function()
local highlight = {
"RainbowRed",
"RainbowYellow",
"RainbowBlue",
"RainbowOrange",
"RainbowGreen",
"RainbowViolet",
"RainbowCyan",
}
require("ibl").setup({
indent = { char = "│", highlight = highlight, },
scope = { enabled = false },
})
local hooks = require("ibl.hooks")
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" })
vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" })
vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" })
vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" })
vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" })
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" })
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" })
end)
end,
},
}
-- nvim/init.lua (if your color scheme does not already provide these highlight groups)
vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75", })
vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B", })
vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF", })
vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66", })
vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379", })
vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD", })
vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2", })