Overview
The configuration uses LuaSnip as the snippet engine, integrated with nvim-cmp for seamless completion.LuaSnip Integration
Loading Snippets
VSCode-style snippets are automatically loaded:lua/user/cmp.lua:11
- Installed snippet plugins (e.g.,
friendly-snippets) - Custom snippet files in VSCode format
Snippet Expansion
nvim-cmp is configured to use LuaSnip for expansion:lua/user/cmp.lua:49
Navigation
Tab Navigation
Tab key intelligently handles snippets:lua/user/cmp.lua:68
- If completion menu is visible → select next item
- If on a snippet trigger → expand it
- If in a snippet → jump to next field
- If at line start/after whitespace → insert tab
- Otherwise → default behavior
Shift-Tab Navigation
Navigate backwards through snippet fields:lua/user/cmp.lua:84
Snippet Format
VSCode Snippet Format
Snippets follow VSCode’s JSON format:prefix: Trigger text to expandbody: Template with tab stops${1:name}: Tab stop 1 with default text “name”$0: Final cursor position
Installing Snippet Packs
Friendly Snippets
A popular collection of snippets for many languages:lua/user/plugins.lua
Language Support
friendly-snippets includes snippets for:- JavaScript/TypeScript
- Python
- Go, Rust, C/C++
- HTML/CSS
- Lua
- And many more…
Creating Custom Snippets
Method 1: VSCode-style Files
Create snippet files in~/.config/nvim/snippets/:
~/.config/nvim/snippets/lua.json
lua/user/cmp.lua
Method 2: Lua Snippets
Define snippets directly in Lua:~/.config/nvim/lua/user/snippets.lua
Snippet Variables
Common Variables
VSCode snippet variables:| Variable | Description |
|---|---|
$TM_SELECTED_TEXT | Currently selected text |
$TM_CURRENT_LINE | Contents of current line |
$TM_FILENAME | Filename of current file |
$TM_FILENAME_BASE | Filename without extension |
$TM_DIRECTORY | Directory of current file |
$CURRENT_YEAR | Current year |
$CURRENT_MONTH | Current month (01-12) |
$CURRENT_DATE | Current day (01-31) |
Example with Variables
Advanced Features
Choice Nodes
Provide multiple options at a tab stop:- Type
logand press Tab - Press
<C-l>to cycle through choices
Dynamic Snippets
Generate content based on context:Conditional Expansion
Expand only in specific contexts:Customization
Snippet Appearance
Customize how snippets appear in completion:lua/user/cmp.lua:103
Snippet Icon
Change the snippet icon:lua/user/cmp.lua:33
Snippet Source Priority
Change when snippets appear:Useful Snippets Examples
Lua Neovim Config
snippets/lua.json
Python
snippets/python.json
Troubleshooting
Snippets Not Loading
Check if LuaSnip is properly initialized:Tab Not Working
Verify the mapping is set:Custom Snippets Not Found
Ensure the path is correct:Commands
| Command | Description |
|---|---|
:LuaSnipEdit | Edit snippets for current filetype |
:LuaSnipUnlinkCurrent | Unlink from current snippet |
Related Pages
nvim-cmp
Completion configuration and integration
LSP Overview
LSP setup and architecture

