Customizing Plugins
Customizing Plugins即用户定制插件。AstroNvim 中并没有集成所有插件,即使AstroNvim Community中已经存在了大量的插件。不过依赖于Lazy的强大特性, AstroNvim 提供了非常简单的定制化功能。
定制插件
默认的 AstroNvim 模版会自动 plugins 目录下的 lua 文件,因此我们只需要在其中创建一个 lua 文件,然后返回 Lazy Spec 就可以实现引入新的插件:
Lua
return {
{
"catppuccin/nvim",
name = "catppuccin",
opts = {
dim_inactive = { enabled = true, percentage = 0.25 },
highlight_overrides = {
mocha = function(c)
return {
Normal = { bg = c.mantle },
Comment = { fg = "#7687a0" },
["@tag.attribute"] = { style = {} },
}
end,
},
},
},
}
上面我们只需要定义在 lua/plugins/catppuccin.lua
就能够引入插件了。
Notes
可以 return 一个列表,例如只需要定义一个 lua/plugins/users.lua
然后返回所有自定义的插件的 Spec 就好了。
覆盖 AstroNvim 插件
如果我们对 AstroNvim 内置的插件和设置不满意,也可以简单的覆盖他们,例如 lua/plugins/overridden.lua
中定义:
Lua
return {
{
"AstroNvim/astrocore",
---@type AstroCoreOpts
opts = { -- extend the plugin options
diagnostics = {
-- disable diagnostics virtual text
virtual_text = false,
},
},
},
-- customize cmp mappings
{
"hrsh7th/nvim-cmp",
-- override the options table that is used
-- in the `require("cmp").setup()` call
opts = function(_, opts)
-- opts parameter is the default options table
-- the function is lazy loaded so cmp is able to be required
local cmp = require("cmp")
-- modify the mapping part of the table
opts.mapping["<C-x>"] = cmp.mapping.select_next_item()
end,
},
-- customize treesitter parsers
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
-- list like portions of a table cannot be merged naturally and require the user to merge it manually
-- check to make sure the key exists
if not opts.ensure_installed then
opts.ensure_installed = {}
end
vim.list_extend(opts.ensure_installed, {
"lua",
"vim",
-- add more arguments for adding more treesitter parsers
})
end,
},
}