From 3e027006325dabc6e4a484c9f73724d8094eb128 Mon Sep 17 00:00:00 2001 From: Lorenzo Murarotto Date: Thu, 24 Oct 2024 12:16:13 +0200 Subject: [PATCH] docs(recipes): add tab completion instructions for luasnip users --- docs/configuration/recipes.md | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/configuration/recipes.md b/docs/configuration/recipes.md index 80cceca79..1fd1cd00c 100644 --- a/docs/configuration/recipes.md +++ b/docs/configuration/recipes.md @@ -25,6 +25,8 @@ override nvim-cmp and add cmp-emoji Use `` for completion and snippets (supertab). +### Without luasnip + ```lua { "hrsh7th/nvim-cmp", @@ -69,6 +71,43 @@ Use `` 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, { + [""] = 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" }), + [""] = 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