diff --git a/.config/nvim/lua/erik/lazy.lua b/.config/nvim/lua/erik/lazy.lua index 9c9415d..b820b9c 100644 --- a/.config/nvim/lua/erik/lazy.lua +++ b/.config/nvim/lua/erik/lazy.lua @@ -112,6 +112,19 @@ require("lazy").setup({ local cmp = require'cmp' cmp.setup({ + -- https://github.com/hrsh7th/nvim-cmp/wiki/Advanced-techniques#disabling-completion-in-certain-contexts-such-as-comments + enabled = function() + -- disable completion in comments + local context = require 'cmp.config.context' + -- keep command mode completion enabled when cursor is in a comment + if vim.api.nvim_get_mode().mode == 'c' then + return true + else + return not context.in_treesitter_capture("comment") + and not context.in_syntax_group("Comment") + end + end, + snippet = { -- REQUIRED - you must specify a snippet engine expand = function(args) @@ -126,13 +139,21 @@ require("lazy").setup({ -- completion = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(), }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = 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. - }), + + -- don't use up/down arrows. Different from the suggested "merge", this replaces the keymaps completely + -- I wouldn't have to have done this if I used HJKL motions when I edit rather than arrow keys + mapping = { + [''] = { i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), }, + [''] = { i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), }, + [''] = { i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), }, + [''] = { i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), }, + [''] = { i = cmp.mapping.confirm({ select = false }), }, + [''] = { i = cmp.mapping.abort(), }, + [''] = { i = cmp.mapping.complete(), }, + [''] = { i = cmp.mapping.scroll_docs(-4) }, + [''] = { i = cmp.mapping.scroll_docs(4) }, + }, + sources = cmp.config.sources({ { name = 'nvim_lsp' }, -- { name = 'vsnip' }, -- For vsnip users.