Skip to content

Commit 402f7cc

Browse files
committed
docs(recipes): add tab completion instructions for luasnip users
1 parent f65087d commit 402f7cc

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/configuration/recipes.md

+39
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ override nvim-cmp and add cmp-emoji
2525

2626
Use `<tab>` for completion and snippets (supertab).
2727

28+
### Without luasnip
29+
2830
```lua
2931
{
3032
"hrsh7th/nvim-cmp",
@@ -69,6 +71,43 @@ Use `<tab>` for completion and snippets (supertab).
6971
}
7072
```
7173

74+
### With luasnip
75+
76+
If the `Luasnip` extra is enabled you should use the following configuration instead:
77+
78+
```lua
79+
{
80+
"hrsh7th/nvim-cmp",
81+
optional = true,
82+
-- See https://www.lazyvim.org/configuration/recipes#supertab
83+
-- See https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
84+
---@param opts cmp.ConfigSchema
85+
opts = function(_, opts)
86+
local cmp = require("cmp")
87+
local luasnip = require("luasnip")
88+
opts.mapping = vim.tbl_extend("force", opts.mapping, {
89+
["<Tab>"] = cmp.mapping(function(fallback)
90+
if cmp.visible() then
91+
-- You could replace select_next_item() with confirm({ select = true }) to get VS Code autocompletion behavior
92+
cmp.select_next_item()
93+
elseif luasnip.locally_jumpable(1) then
94+
luasnip.jump(1)
95+
else
96+
fallback()
97+
end
98+
end, { "i", "s" }),
99+
["<S-Tab>"] = cmp.mapping(function(fallback)
100+
if cmp.visible() then
101+
cmp.select_prev_item()
102+
elseif luasnip.locally_jumpable(-1) then
103+
luasnip.jump(-1)
104+
else
105+
fallback()
106+
end
107+
end, { "i", "s" }),
108+
})
109+
end,
110+
}
72111
## Change surround mappings
73112

74113
```lua

0 commit comments

Comments
 (0)