Skip to content

Commit 89439ff

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

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/configuration/recipes.md

+38
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,42 @@ 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+
-- See https://www.lazyvim.org/configuration/recipes#supertab
80+
-- See https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
81+
return {
82+
"hrsh7th/nvim-cmp",
83+
optional = true,
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+
cmp.select_next_item()
92+
elseif luasnip.locally_jumpable(1) then
93+
luasnip.jump(1)
94+
else
95+
fallback()
96+
end
97+
end, { "i", "s" }),
98+
["<S-Tab>"] = cmp.mapping(function(fallback)
99+
if cmp.visible() then
100+
cmp.select_prev_item()
101+
elseif luasnip.locally_jumpable(-1) then
102+
luasnip.jump(-1)
103+
else
104+
fallback()
105+
end
106+
end, { "i", "s" }),
107+
})
108+
end,
109+
}
72110
## Change surround mappings
73111

74112
```lua

0 commit comments

Comments
 (0)