Plugins


The lazy.nvim documentation is very thorough and provides pretty much any information that will be required to configure your plugins. The main thing we wanted to touch on was a few patterns that can be used inside the plugin spec files.

These can be helpful for organizing plugins or groups of common plugins.

Single Plugin per File

In some cases it makes sense to have a single plugin configured by a configuration file. In this case, the configuration file should return a Lua table containing the path to the plugin, and any additional configuration for that plugin.

return {
    "plugin/name",
    enabled = true,
    event = { "BufReadPre", "BufNewFile" },
    opts = {
        ...
    }
}

Multiple Plugins per File

return {
    {
        "plugin/one",
        enabled = true,
        ...
    },
    {
        "plugin/two",
        -- the enabled key allows plugins to be easily disabled
        enabled = false,
        ...
    },
    -- if using the default config this can be simplified to just the plugin path
    "plugin/three"
}

Helpers

The plugin file needs to return either a Lua table configuring a plugin, or a list of Lua tables configuring one or more plugins. Prior to the return statement, the plugin file can include additional configuration, set variables, require other files, define user-commands and/or auto-commands, etc.

-- require functions from a command module for reuseability
local helpers = require("helpers")

-- define local functions
local some_function = function()
    ...
end

-- this can also be a list of tables configuring multiple plugins
return {
    "plugin/name",
    some_key = some_function(),
    another_key = helpers.other_function("arg")
}