Skip to content

Commit

Permalink
docs(recipes): add tab completion instructions for luasnip users
Browse files Browse the repository at this point in the history
  • Loading branch information
murar8 committed Oct 24, 2024
1 parent f65087d commit 3e02700
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions docs/configuration/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ override nvim-cmp and add cmp-emoji

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

### Without luasnip

```lua
{
"hrsh7th/nvim-cmp",
Expand Down Expand Up @@ -69,6 +71,43 @@ Use `<tab>` for completion and snippets (supertab).
}
```

### With luasnip

If the `Luasnip` extra is enabled you should use the following configuration instead:

```lua
-- See https://www.lazyvim.org/configuration/recipes#supertab
-- See https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
return {
"hrsh7th/nvim-cmp",
optional = true,
---@param opts cmp.ConfigSchema
opts = function(_, opts)
local cmp = require("cmp")
local luasnip = require("luasnip")
opts.mapping = vim.tbl_extend("force", opts.mapping, {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
-- You could replace select_next_item() with confirm({ select = true }) to get VS Code autocompletion behavior
cmp.select_next_item()
elseif luasnip.locally_jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
})
end,
}
## Change surround mappings

```lua
Expand Down

0 comments on commit 3e02700

Please sign in to comment.