From c5842ac5eceb52369b3f6ed12ad8289f2a7f94d4 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Sat, 8 Apr 2023 01:37:35 +0100 Subject: [PATCH] lsp completion selection behaviour now more similar to default vim completion. - Selecting completion items now changes text in the buffer directly without having to confirm it with . --- .config/nvim/after/plugin/lsp.lua | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua index 16110c0..e6d26de 100644 --- a/.config/nvim/after/plugin/lsp.lua +++ b/.config/nvim/after/plugin/lsp.lua @@ -1,4 +1,14 @@ local lsp = require('lsp-zero').preset({}) +local cmp = require('cmp'); + +-- Set the lsp autocomplete to put text from selection into the buffer. +-- +-- This setup_nvim_cmp function is deprecated, though this seems to be +-- the cleanest solution as of lsp-zero v2.x. A fallback solution is +-- commented out below. +lsp.setup_nvim_cmp({ + select_behavior = cmp.SelectBehavior.Insert +}) vim.diagnostic.config({ virtual_text = true @@ -16,3 +26,29 @@ end) require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls()) lsp.setup() + +-- Below commented code is a fallback for when the setup_nvim_cmp() +-- is gone +-- +-- This is adapted from the defaults provided by lsp-zero +-- - see https://github.com/VonHeikemen/lsp-zero.nvim/blob/v2.x/lua/lsp-zero/cmp.lua +-- +--local select_opts = { behavior = cmp.SelectBehavior.Insert } +--cmp.setup({ +-- mapping = { +-- [''] = cmp.mapping(function() +-- if cmp.visible() then +-- cmp.select_prev_item(select_opts) +-- else +-- cmp.complete() +-- end +-- end), +-- [''] = cmp.mapping(function() +-- if cmp.visible() then +-- cmp.select_next_item(select_opts) +-- else +-- cmp.complete() +-- end +-- end), +-- } +--})