This tutorial is purely for me to keep my plugin configuration style in mind.
- The entire configuration should be written in lua, never use vimscript;
- All configuration files should be linted with luacheck;
Each file should contain the configuration of only one plugin. This rule increases the modularity and convenience of the configuration.
Always leave a NOTE comment at the beginning of the configuration file to remember why you need the plugin in the first place. It is desirable to leave a comment about each dependency as well.
If a plugin has dependencies, all of them must be specified in the configuration. Even if they are already installed or are dependencies of other plugins. Otherwise, if one day you have to abandon a plugin, its dependencies may be lost and cause errors in other plugins.
Favor opts over config. Use config() only in very complex cases.
Do not copy the default settings into configuration. It just doesn't make sense.
Stick to a specific order of configuration sections.
- Plugin address.
- lazy
- event
- dependencies
- keys
- opts/config()
- build
- Other specific sections
Never forget to add hotkey information to the which-key plugin when you create a new one.
If you need to add support for a new language, there are a few rules of thumb.
For language support, I use LSP. To add an LSP, follow the steps below.
- Add the language server from Mason to the ./lua/plugin/lsp/mason.lua file, mason_lspconfig.setup section.
- Add the language server from Mason to the ./lua/plugin/lsp/lspconfig.lua.
- Add the language to the ./lua/plugin/editor/treesitter.lua.
Always add linters if you can.
- Add the linter to the ./lua/plugin/lsp/mason.lua file, mason_tool_installer.setup section.
- Add the linter to the ./lua/plugin/lsp/lint.lua file.
Always add formatters if you can.
- Add the linter to the ./lua/plugin/lsp/mason.lua file, mason_tool_installer.setup section.
- Add the linter to the ./lua/plugin/lsp/conform.lua file.
Add comments if the name of the lsp/linter/formatter doesn't speak for itself. F.e. black for python.