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 + }, + +}