Neovim for Beginners — Snippets using Lua
In the previous article, we configured snippets plugins and wrote our snippets using Lua. We will build on the existing setup and improve the configuration to help us code more efficiently. We are going to
- Refactor existing configuration to use Lua snippets loader.
- Go through Luasnip basics.
- Develop code snippets to help us code more efficiently.
This article is part of the Neovim for Beginners series.
The Neovim configuration files can be found in this repository.
Lua Snippets Loader
In the previous article, we separated our snippets by the languages under the
lua/config/snip/snippets folder, and use an
autocmd to load the snippet files. For Luasnip, there is a better way to do this now. We are going to refactor our configuration to use the Lua snippets loader.
- We use the Lua snippets loader to lazy load snippet files under the
- We configure a command called
LuaSnipEditto edit the snippet files.
Once loaded, the snippet files will be automatically reloaded on save (
Before we deep dive into the details, we need to understand the basics of Luasnip. In LuaSnip, snippets are made up of
nodes. These can contain either