From 6cbcb83a88e55c9d4ce5c9f60b5734a63dc10448 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Wed, 15 Nov 2023 12:17:53 -0800 Subject: [PATCH] cmp.lua separated from config.lua -- appears to work --- init.lua | 1 + lua/jim/cmp.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++ lua/jim/config.lua | 58 ++-------------------------------------------- 3 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 lua/jim/cmp.lua diff --git a/init.lua b/init.lua index 3e9a70d0..c07307bb 100644 --- a/init.lua +++ b/init.lua @@ -5,6 +5,7 @@ -- -- main config file require 'jim.config' -- lua/jim/config.lua +require 'jim.cmp' -- lua/jim/cmp.lua require 'jim.keymaps' -- lua/jim/keymaps.lua require 'jim.settings' -- lua/jim/settings.lua require 'jim.luasnip' -- lua/jim/luasnip.lua diff --git a/lua/jim/cmp.lua b/lua/jim/cmp.lua new file mode 100644 index 00000000..eafe1186 --- /dev/null +++ b/lua/jim/cmp.lua @@ -0,0 +1,56 @@ +-- nvim-cmp configuration +-- [[ Configure hrsh7th nvim-cmp ]] +-- See `:help cmp` +local cmp = require 'cmp' +local luasnip = require 'luasnip' +local ls = require 'luasnip' + + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + + ----------------------------------------------------------------- + --With multiple items, TAB selects NEXT item (CR to complete) + ----------------------------------------------------------------- + -- + -- + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + 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' }), + }, + sources = { -- need nvim-cmp extensions? + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + { name = 'buffer', keyword_length = 5 }, + }, +} diff --git a/lua/jim/config.lua b/lua/jim/config.lua index 4f9a3763..66adc4a7 100644 --- a/lua/jim/config.lua +++ b/lua/jim/config.lua @@ -613,61 +613,7 @@ mason_lspconfig.setup_handlers { end, } --- nvim-cmp configuration --- [[ Configure hrsh7th nvim-cmp ]] --- See `:help cmp` -local cmp = require 'cmp' -local luasnip = require 'luasnip' -local ls = require 'luasnip' - -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete {}, - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - - --------------------------------------- - -- TJ says don't use this way - --------------------------------------- - -- - -- TAB selects NEXT item (CR to complete) - -- [''] = cmp.mapping(function(fallback) - -- if cmp.visible() then - -- cmp.select_next_item() - -- elseif luasnip.expand_or_locally_jumpable() then - -- luasnip.expand_or_jump() - -- 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' }), - }, - sources = { -- need nvim-cmp extensions? - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - { name = 'buffer', keyword_length = 5 }, - }, -} - +-- cmp WAS here +-- -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et