From 1e2a6dc5d2707c64fd950dc0841623fdc856367a Mon Sep 17 00:00:00 2001 From: zymon Date: Tue, 27 Aug 2024 14:36:52 +0200 Subject: [PATCH] completion engine --- lua/znvim/plugins/cmp.lua | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lua/znvim/plugins/cmp.lua diff --git a/lua/znvim/plugins/cmp.lua b/lua/znvim/plugins/cmp.lua new file mode 100644 index 0000000..9822c41 --- /dev/null +++ b/lua/znvim/plugins/cmp.lua @@ -0,0 +1,62 @@ +return { + + { + "https://github.com/hrsh7th/nvim-cmp", + dependencies = { + "https://github.com/hrsh7th/cmp-buffer", + "https://github.com/hrsh7th/cmp-path", + "https://github.com/hrsh7th/cmp-cmdline", + }, + event = { "InsertEnter", "CmdlineEnter", "BufReadPost" }, + config = function() + local cmp = require("cmp") + cmp.setup({ + preselect = cmp.PreselectMode.None, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping.abort(), + }), + sources = cmp.config.sources({ + { + name = "buffer", + option = { keyword_length = 3 }, + }, + }), + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, item) + item.kind = item.kind + item.menu = ({ + buffer = "[buf]", + path = "[path]", + cmdline = "[cmd]", + })[entry.source.name] or entry.source.name + return item + end, + }, + }) + + cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' }, + { name = 'cmdline' } + }) + }) + end + }, + +}