aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/pm/plugins/nvim-cmp
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-15 20:28:13 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-15 20:28:13 +0200
commit17e319a4455f3135ed3cc759dee8ba5034fde75b (patch)
tree6d07c1875ae2736a5f3eb026a243328ab5c73fca /.config/nvim/lua/pm/plugins/nvim-cmp
parent346854ff3ea83202de7437f01f1c1c336f4c3edf (diff)
update vim configHEADmaster
Diffstat (limited to '.config/nvim/lua/pm/plugins/nvim-cmp')
-rw-r--r--.config/nvim/lua/pm/plugins/nvim-cmp/load.lua20
-rw-r--r--.config/nvim/lua/pm/plugins/nvim-cmp/setup.lua86
2 files changed, 106 insertions, 0 deletions
diff --git a/.config/nvim/lua/pm/plugins/nvim-cmp/load.lua b/.config/nvim/lua/pm/plugins/nvim-cmp/load.lua
new file mode 100644
index 0000000..25509d5
--- /dev/null
+++ b/.config/nvim/lua/pm/plugins/nvim-cmp/load.lua
@@ -0,0 +1,20 @@
+return {
+ 'hrsh7th/nvim-cmp',
+ event = "InsertEnter",
+ dependencies = {
+ {
+ "L3MON4D3/LuaSnip",
+ dependencies = "rafamadriz/friendly-snippets",
+ opts = { history = true, updateevents = "TextChanged,TextChangedI" },
+ config = function(_, opts)
+ require("luasnip").config.set_config(opts)
+ end,
+ },
+ {
+ "saadparwaiz1/cmp_luasnip",
+ "hrsh7th/cmp-nvim-lua",
+ "hrsh7th/cmp-nvim-lsp",
+ "hrsh7th/cmp-path",
+ },
+ },
+}
diff --git a/.config/nvim/lua/pm/plugins/nvim-cmp/setup.lua b/.config/nvim/lua/pm/plugins/nvim-cmp/setup.lua
new file mode 100644
index 0000000..c1c9644
--- /dev/null
+++ b/.config/nvim/lua/pm/plugins/nvim-cmp/setup.lua
@@ -0,0 +1,86 @@
+local cmp = require("cmp")
+require("luasnip.loaders.from_vscode").lazy_load()
+
+local function border(hl_name)
+ return {
+ { "╭", hl_name },
+ { "─", hl_name },
+ { "╮", hl_name },
+ { "│", hl_name },
+ { "╯", hl_name },
+ { "─", hl_name },
+ { "╰", hl_name },
+ { "│", hl_name },
+ }
+end
+
+cmp.setup {
+ completion = {
+ completeopt = "menu,menuone",
+ },
+
+ window = {
+ completion = {
+ border = border "CmpBorder",
+ side_padding = 1,
+ winhighlight = "Normal:CmpPmenu,CursorLine:CmpSel,Search:None",
+ scrollbar = true,
+ },
+ documentation = {
+ border = border "CmpDocBorder",
+ winhighlight = "Normal:CmpDoc",
+ },
+ },
+ 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(),
+ ["<C-d>"] = cmp.mapping.scroll_docs(-4),
+ ["<C-f>"] = cmp.mapping.scroll_docs(4),
+ ["<C-Space>"] = cmp.mapping.complete(),
+ ["<C-e>"] = cmp.mapping.close(),
+
+ ["<CR>"] = cmp.mapping.confirm {
+ behavior = cmp.ConfirmBehavior.Insert,
+ select = true,
+ },
+
+ ["<Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif require("luasnip").expand_or_jumpable() then
+ vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
+ else
+ fallback()
+ end
+ end, { "i", "s" }),
+
+ ["<S-Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ elseif require("luasnip").jumpable(-1) then
+ vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
+ else
+ fallback()
+ end
+ end, { "i", "s" }),
+ },
+ sources = {
+ { name = "nvim_lsp" },
+ { name = "luasnip" },
+ { name = "buffer" },
+ { name = "nvim_lua" },
+ { name = "path" },
+ },
+}
+
+local signs = { Error = "󰀨 ", Warn = " ", Hint = " ", Info = " " }
+for type, icon in pairs(signs) do
+ local hl = "DiagnosticSign" .. type
+ vim.fn.sign_define(hl, { text = icon, texthl= hl, numhl = hl })
+end