Snippets
Learn how to manage and use custom snippets in NyxVim using LuaSnip
Introduction to Snippets
Snippets are powerful tools that allow you to quickly insert pre-defined code templates into your editor. NyxVim uses the LuaSnip
plugin for handling snippets, providing a flexible and efficient snippet management system.
By default, NyxVim includes the friendly-snippets
plugin, which offers a wide range of snippets for many programming languages.
LuaSnip Overview
LuaSnip is a snippet engine for Neovim written in Lua. It offers advanced features like:
- Dynamic snippets
- Conditional expansion
- Nested snippets
- And more!
To get the most out of LuaSnip, we recommend reading the official LuaSnip documentation.
Configuring Snippet Paths
NyxVim provides global variables to specify the paths for your custom snippets. You can set these in your configuration:
vim.fn.stdpath("config")
returns the path to your Neovim configuration folder.
Creating Custom Snippets
To create your own snippets, you can use any of the supported formats (VSCode, SnipMate, or Lua). Here’s an example of a Lua snippet:
This snippet creates a ternary operator template that can be used in any file type.
Using Snippets
To use a snippet:
- Enter insert mode
- Type the snippet trigger
- Press the expansion key (usually
<Tab>
)
You can use the :LuaSnipListAvailable
command to see all available snippets for the current file type.
Best Practices
- Organize snippets: Keep your snippets organized by language or purpose.
- Use descriptive names: Choose clear, descriptive names for your snippets.
- Leverage dynamic snippets: Use Lua’s power to create dynamic, context-aware snippets.
- Keep snippets DRY: Avoid duplicating code in your snippets.
Troubleshooting
If you’re having issues with snippets:
- Check that the snippet path is correctly set
- Ensure the snippet file is in the correct format
- Verify that the snippet trigger is correct
- Use
:LuaSnipListAvailable
to check if the snippet is recognized
Need Help?
If you’re having trouble with any NyxVim features or have questions:
- Check our FAQ section for common questions and answers.
- Join our Discord community to chat with other NyxVim users.
- Participate in GitHub Discussions to engage with the NyxVim community, share ideas, and get help.
- For bug reports or feature requests, open an issue on our GitHub repository.