aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/nvim/lua/plugins/cmp.lua
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-03-17 13:09:00 -0500
committerToby Vincent <tobyv13@gmail.com>2022-03-17 13:09:00 -0500
commitea8f210bd97b48d2ffd664f966872a8e51f1e306 (patch)
tree18f33ee3d82cc7399e367f59a64d4067661cac35 /nvim/lua/plugins/cmp.lua
parenta3d6669ce88b8690e53429773d7e30056d86e135 (diff)
feat: initial working nvim
Diffstat (limited to 'nvim/lua/plugins/cmp.lua')
-rw-r--r--nvim/lua/plugins/cmp.lua138
1 files changed, 138 insertions, 0 deletions
diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua
new file mode 100644
index 0000000..2729b0e
--- /dev/null
+++ b/nvim/lua/plugins/cmp.lua
@@ -0,0 +1,138 @@
+-- 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,
+ }
+
+})
+
+-- 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)
+ :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
+ }),
+
+ ["<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")
+
+-- local source_mapping = {
+-- nvim_lsp = "[LSP]",
+-- nvim_lua = "[Lua]",
+-- path = "[Path]",
+-- buffer = "[Buffer]",
+-- luasnip = "[LuaSnip]",
+-- nvim_lsp_signature_help = "[LspSignatureHelp]",
+-- calc = "[Calc]",
+-- }
+
+-- cmp.setup({
+-- 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)
+-- vim_item.kind = require("lspkind").presets.default[vim_item.kind]
+-- local menu = source_mapping[entry.source.name]
+-- vim_item.menu = menu
+-- return vim_item
+-- end,
+-- },
+-- -- Installed sources
+-- sources = {
+-- -- { name = 'path' },
+-- { name = "nvim_lsp" },
+-- { name = "nvim_lua" },
+-- { name = 'path' },
+-- { name = "luasnip" },
+-- { name = "buffer", keyword_length = 1 },
+-- { name = 'nvim_lsp_signature_help' },
+-- { name = 'calc' },
+-- },
+-- }) \ No newline at end of file