diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-09-24 02:55:49 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-09-24 02:55:49 +0200 |
| commit | 3cf613ec7c90ab4933728b0f19e49b0c955c17bb (patch) | |
| tree | 765e58766936b5228ad473ad77dfbf4353f173e9 /common/nvim/lua/plugins/cmp.lua | |
| parent | ef51a60993197ed3bbd1003522f98f0a898d34c6 (diff) | |
| parent | 966d12ac730c83da90d60ab24eae539b2ea69441 (diff) | |
| download | dotfiles-3cf613ec7c90ab4933728b0f19e49b0c955c17bb.tar.gz dotfiles-3cf613ec7c90ab4933728b0f19e49b0c955c17bb.zip | |
Add 'common/nvim/' from commit '966d12ac730c83da90d60ab24eae539b2ea69441'
git-subtree-dir: common/nvim
git-subtree-mainline: ef51a60993197ed3bbd1003522f98f0a898d34c6
git-subtree-split: 966d12ac730c83da90d60ab24eae539b2ea69441
Diffstat (limited to 'common/nvim/lua/plugins/cmp.lua')
| -rwxr-xr-x | common/nvim/lua/plugins/cmp.lua | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/common/nvim/lua/plugins/cmp.lua b/common/nvim/lua/plugins/cmp.lua new file mode 100755 index 0000000..7de04ad --- /dev/null +++ b/common/nvim/lua/plugins/cmp.lua @@ -0,0 +1,67 @@ +local M = {} + +--- Setup and configure nvim-cmp +-- This function initializes and configures the completion plugin +-- @return boolean True if setup was successful, false otherwise +function M.setup() + -- Check Neovim version + local nvim_version = vim.version() + if nvim_version.major == 0 and nvim_version.minor < 5 then + return false + end + + -- Try to load required modules + local cmp = pcall(require, 'cmp') and require('cmp') + if not cmp then + return false + end + + local luasnip_ok, luasnip = pcall(require, 'luasnip') + if not luasnip_ok then + vim.notify("luasnip not found, some features may be limited", vim.log.levels.WARN) + end + + -- Setup nvim-cmp + cmp.setup({ + snippet = { + expand = function(args) + if luasnip_ok then luasnip.lsp_expand(args.body) end + end, + }, + mapping = cmp.mapping.preset.insert({ + ['<C-Space>'] = cmp.mapping.complete(), + ['<CR>'] = cmp.mapping.confirm({ select = true }), + ['<Tab>'] = cmp.mapping.select_next_item(), + ['<S-Tab>'] = cmp.mapping.select_prev_item(), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'buffer' }, + }), +}) + +vim.cmd([[ + highlight! link CmpItemMenu Comment + " gray + highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080 + " blue + highlight! CmpItemAbbrMatch guibg=NONE guifg=#569CD6 + highlight! CmpItemAbbrMatchFuzzy guibg=NONE guifg=#569CD6 + " light blue + highlight! CmpItemKindVariable guibg=NONE guifg=#9CDCFE + highlight! CmpItemKindInterface guibg=NONE guifg=#9CDCFE + highlight! CmpItemKindText guibg=NONE guifg=#9CDCFE + " pink + highlight! CmpItemKindFunction guibg=NONE guifg=#C586C0 + highlight! CmpItemKindMethod guibg=NONE guifg=#C586C0 + " front + highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4 + highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4 + highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4 + ]]) + + return true +end + +return M |
