From d4f71ddb0fa375b43c58b3f56d8a7db53bd93947 Mon Sep 17 00:00:00 2001 From: Andy Teijelo Date: Mon, 18 Dec 2023 09:33:02 -0500 Subject: [PATCH] More Tab key fixes --- lua/config/autocmds.lua | 13 +++++++++++++ lua/config/options.lua | 1 + lua/plugins/core.lua | 13 ++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index 27e9e06..a9b1e32 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -1,3 +1,16 @@ -- Autocmds are automatically loaded on the VeryLazy event -- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua -- Add any additional autocmds here + +-- stop snippets when you leave to normal mode +vim.api.nvim_create_autocmd({ "ModeChanged" }, { + callback = function() + if + ((vim.v.event.old_mode == "s" and vim.v.event.new_mode == "n") or vim.v.event.old_mode == "i") + and require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, +}) diff --git a/lua/config/options.lua b/lua/config/options.lua index 0d872d8..81ebe76 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -10,3 +10,4 @@ vim.opt.pumblend = 0 vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.g.autoformat = false +vim.opt.completeopt = "menuone,noselect,preview" diff --git a/lua/plugins/core.lua b/lua/plugins/core.lua index f7833ae..8fef8ac 100644 --- a/lua/plugins/core.lua +++ b/lua/plugins/core.lua @@ -62,6 +62,16 @@ return { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), } + opts.formatting = { + format = function(entry, vim_item) + vim_item.abbr = string.sub(vim_item.abbr, 1, 40) + return vim_item + end, + } + opts.preselect = cmp.PreselectMode.None + opts.completion = { + completeopt = "menuone,noselect,preview", + } opts.mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), @@ -69,7 +79,8 @@ return { [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + -- [""] = cmp.config.disable, [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true,