Snippets
LuaSnip is a snippet Engine for Neovim written in Lua.
Installation⚑
It comes preinstalled with lazyvim. You can see the default configuration here.
Add your custom snippets⚑
return {
{
"L3MON4D3/LuaSnip",
dependencies = {
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
require("luasnip.loaders.from_lua").lazy_load({ paths = "./lua/snippets" })
end,
},
},
}
And store your snippets in ./lua/snippets
. You can write snippets in You have two main choices to write snippets: use SnipMate/VS Code snippets (easier) or write snippets in Lua (more complex but also more feature-rich).
If you want to learn to write lua snippets check these resources for new users.
Usage⚑
Lazyvim comes with the friendly-snippets
installed by default. It's good to have it cloned locally to browse the available ones.
Transform selected text⚑
It can only be used on snippets that use TM_SELECTED_TEXT
:
You'd have to
- Select some text in visual mode
- Hit whatever you set as
store_selection_keys
. - Expand that snippet.
It looks like the default binding for store_selection_keys
is <Tab>
. If it's not you can configure it with.
require("luasnip").config.setup({store_selection_keys="<Tab>"})