diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-03-19 14:27:18 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-03-19 14:27:18 -0500 |
commit | 209c15c008251cd96f0d4ae6a4c797a1ccb1e9bd (patch) | |
tree | e4bc0a7e2a0aea5c1901423910d88ebc72e35d82 /nvim/lua/plugins/cmp.lua | |
parent | 95d6897c7ae05074a4c034d180c834c8534a2582 (diff) |
feat: nvim working mostly
Diffstat (limited to 'nvim/lua/plugins/cmp.lua')
-rw-r--r-- | nvim/lua/plugins/cmp.lua | 127 |
1 files changed, 54 insertions, 73 deletions
diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua index 2729b0e..1a13863 100644 --- a/nvim/lua/plugins/cmp.lua +++ b/nvim/lua/plugins/cmp.lua @@ -1,87 +1,68 @@ --- Set completeopt to have a better completion experience -vim.o.completeopt = 'menuone,noselect' -local cmp = require 'cmp' - -cmp.setup({ - completion = { - -- completeopt = 'menu,menuone,noinsert', - }, - snippet = { - expand = function(args) require('luasnip').lsp_expand(args.body) end - }, - formatting = { - format = function(entry, vim_item) - -- fancy icons and a name of kind - vim_item.kind = require("lspkind").presets.default[vim_item.kind] - -- set a name for each source - vim_item.menu = ({ - buffer = "[Buff]", - nvim_lsp = "[LSP]", - luasnip = "[LuaSnip]", - nvim_lua = "[Lua]", - latex_symbols = "[Latex]" - })[entry.source.name] - return vim_item - end - }, - sources = { - {name = 'nvim_lsp'}, - {name = 'nvim_lua'}, - {name = 'path'}, - {name = 'luasnip'}, - {name = 'buffer', keyword_length = 1}, - {name = 'calc'} - }, - experimental = { - -- ghost_text = true, - } - -}) +local status_ok, cmp = pcall(require, "cmp") +if not status_ok then + return +end -- Require function for tab to work with LUA-SNIP local has_words_before = function() local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and - vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, - col) + vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col) :match("%s") == nil end cmp.setup({ - mapping = { - ['<C-Space>'] = cmp.mapping.complete(), - ['<C-e>'] = cmp.mapping.close(), - ['<C-u>'] = cmp.mapping.scroll_docs(-4), - ['<C-d>'] = cmp.mapping.scroll_docs(4), - ['<CR>'] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = false - }), + completion = { + completeopt = 'menu,menuone,noinsert', + }, + snippet = { + expand = function(args) require('luasnip').lsp_expand(args.body) end + }, + mapping = { + ['<C-p>'] = cmp.mapping.select_prev_item(), + ['<C-n>'] = cmp.mapping.select_next_item(), + -- Add tab support + ['<S-Tab>'] = cmp.mapping.select_prev_item(), + ['<Tab>'] = cmp.mapping.select_next_item(), + ['<C-d>'] = cmp.mapping.scroll_docs(-4), + ['<C-u>'] = cmp.mapping.scroll_docs(4), + ['<C-Space>'] = cmp.mapping.complete(), + ['<C-e>'] = cmp.mapping.close(), + ['<CR>'] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }) + }, + formatting = { + format = function(entry, vim_item) + -- fancy icons and a name of kind + vim_item.kind = require("lspkind").presets.default[vim_item.kind] + -- set a name for each source + vim_item.menu = ({ + buffer = "[Buff]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[Latex]" + })[entry.source.name] + return vim_item + end + }, + sources = { + {name = 'nvim_lsp'}, + {name = 'nvim_lua'}, + {name = 'path'}, + {name = 'luasnip'}, + {name = 'buffer', keyword_length = 1}, + {name = 'calc' } + }, + experimental = { + -- ghost_text = true, + } - ["<Tab>"] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, {"i", "s"}), +}) - ["<S-Tab>"] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, {"i", "s"}) - } -}) -- local luasnip = require("luasnip") @@ -135,4 +116,4 @@ cmp.setup({ -- { name = 'nvim_lsp_signature_help' }, -- { name = 'calc' }, -- }, --- })
\ No newline at end of file +-- }) |