A template for creating Neovim plugins with best practices and standardized structure
Features β’ Requirements β’ Installation β’ Usage β’ Configuration β’ Development β’ Contributing β’ License β’ Discussions
This repository provides a template for creating Neovim plugins with a standardized structure and best practices. It includes:
- Complete plugin structure with entry points
- Documentation templates
- Test framework setup
- Code quality tools integration
- GitHub workflows for CI/CD
- Community health files
- π Complete Structure - All necessary files and directories for a Neovim plugin
- π Documentation - Templates for help docs and README
- π§ͺ Testing - Plenary-based test setup with minimal configuration
- β¨ Code Quality - StyLua and Luacheck configuration
- π CI/CD - GitHub Actions workflows for testing, linting and releases
- π₯ Community - Templates for issues, PRs, and contributing guidelines
- Neovim >= 0.8.0
- Git for version control
- (Optional) StyLua for code formatting
- (Optional) Luacheck for static analysis
-
Use this template to create a new repository:
git clone https://github.com/greggh/neovim-plugin-template.git my-awesome-plugin cd my-awesome-plugin -
Run the setup script to customize the template:
./scripts/setup.sh
-
Update the documentation files with your plugin-specific information
Using lazy.nvim:
{
"greggh/plugin-name",
dependencies = {
-- Add dependencies here
},
config = function()
require("plugin-name").setup({
-- Your configuration
})
end
}Using packer.nvim:
use {
'greggh/plugin-name',
requires = {
-- Add dependencies here
},
config = function()
require('plugin-name').setup({
-- Your configuration
})
end
}Using vim-plug:
Plug 'greggh/plugin-name'
" In your init.vim after plug#end():
lua require('plugin-name').setup({})After installation, you can use the plugin with the following commands:
:PluginNameCommand " Execute the plugin's main function
:PluginNameToggle " Toggle the plugin on/offKey mappings (if using which-key):
<leader>pf- Execute the plugin's main function<leader>pt- Toggle the plugin on/off
Default configuration:
require("plugin-name").setup({
enabled = true,
debug = false,
-- Add other options here
})| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean |
true |
Enable/disable plugin |
debug |
boolean |
false |
Enable debug logging |
-
Clone the repository:
git clone https://github.com/username/plugin-name.git cd plugin-name -
Install development dependencies:
- Neovim 0.8+
- Luacheck for linting
- StyLua for formatting
-
Set up pre-commit hooks (important first step!):
./scripts/setup-hooks.sh
This will enable automatic formatting, linting, and testing before each commit. Make sure to run this before making any changes to ensure code quality.
.
βββ lua/
β βββ plugin-name/ # Plugin code
β βββ init.lua # Main entry point
βββ plugin/
β βββ plugin-name.lua # Plugin load script
βββ doc/
β βββ plugin-name.txt # Help documentation
βββ tests/
β βββ minimal-init.lua # Minimal config for testing
β βββ spec/ # Test specifications
β βββ plugin_spec.lua
βββ .github/ # GitHub specific files
βββ .githooks/ # Git hooks for development
βββ scripts/ # Development scripts
βββ .stylua.toml # StyLua configuration
βββ .luacheckrc # Luacheck configuration
βββ README.md # This file
Before making changes, ensure your development environment is set up with pre-commit hooks:
./scripts/setup-hooks.shRun tests with:
make testOr manually:
nvim --headless -u tests/minimal-init.lua -c "lua require('plenary.test_harness').test_directory('tests/spec')"Format code with StyLua:
stylua .Lint code with Luacheck:
luacheck .Both tools are integrated with the pre-commit hooks when using hooks-util.
Contributions are welcome! Here's how to contribute to this template:
- Fork the repository
- Create a feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
Please make sure to:
- Follow the coding style (run StyLua)
- Add tests for new features
- Update documentation as needed
This template is released under the MIT License. See the LICENSE file for details.
- Neovim - The core editor
- lazy.nvim - Plugin manager
- plenary.nvim - Testing framework
- StyLua - Lua formatter
- Luacheck - Lua linter
- hooks-util - Git hooks framework
Have questions or ideas? Join the conversation in GitHub Discussions.
- Questions: For help with using or developing the plugin
- Ideas: Suggest new features or improvements
- Show and Tell: Share how you're using this plugin
- General: For any other topics related to this plugin
Made with β€οΈ by greggh