summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/cmp.lua
diff options
context:
space:
mode:
authorfschildt <florian.schildt@protonmail.com>2025-09-30 15:16:00 +0200
committerfschildt <florian.schildt@protonmail.com>2025-09-30 15:16:00 +0200
commit887eb639e849966e64d57a4eda521b6c21e11f7a (patch)
treedb423d03b3b7b06f6a7ce5f63c5ba51d0b961c6b /.config/nvim/lua/plugins/cmp.lua
add neovim config
Diffstat (limited to '.config/nvim/lua/plugins/cmp.lua')
-rw-r--r--.config/nvim/lua/plugins/cmp.lua93
1 files changed, 93 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua
new file mode 100644
index 0000000..7126173
--- /dev/null
+++ b/.config/nvim/lua/plugins/cmp.lua
@@ -0,0 +1,93 @@
+return {
+ {
+ "hrsh7th/nvim-cmp",
+ event = { "InsertEnter", "CmdlineEnter" }, -- Load on insert or cmdline mode
+ dependencies = {
+ "hrsh7th/cmp-nvim-lsp", -- LSP completion source
+ "hrsh7th/cmp-buffer", -- Buffer completion source
+ "hrsh7th/cmp-path", -- Path completion source
+ "hrsh7th/cmp-cmdline", -- Cmdline completion source
+ "L3MON4D3/LuaSnip", -- Snippet engine
+ "saadparwaiz1/cmp_luasnip", -- LuaSnip completion source
+ "rafamadriz/friendly-snippets", -- Predefined snippets
+ "onsails/lspkind.nvim", -- Icons for completion items
+ },
+ config = function()
+ local cmp = require("cmp")
+ local luasnip = require("luasnip")
+ local lspkind = require("lspkind")
+
+ -- Load friendly-snippets
+ require("luasnip.loaders.from_vscode").lazy_load()
+
+ cmp.setup {
+ snippet = {
+ expand = function(args)
+ luasnip.lsp_expand(args.body)
+ end,
+ },
+ mapping = cmp.mapping.preset.insert({
+ ["<C-b>"] = cmp.mapping.scroll_docs(-4), -- Scroll up docs
+ ["<C-f>"] = cmp.mapping.scroll_docs(4), -- Scroll down docs
+ ["<C-Space>"] = cmp.mapping.complete(), -- Trigger completion
+ ["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept selection
+ ["<Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ 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" }),
+ }),
+ sources = cmp.config.sources({
+ { name = "nvim_lsp" }, -- LSP completions
+ { name = "luasnip" }, -- Snippet completions
+ { name = "buffer" }, -- Buffer completions
+ { name = "path" }, -- Path completions
+ }),
+ formatting = {
+ format = lspkind.cmp_format({
+ mode = "symbol_text", -- Show symbol and text
+ maxwidth = 50, -- Limit width
+ ellipsis_char = "...", -- Truncation character
+ }),
+ },
+ window = {
+ completion = cmp.config.window.bordered(), -- Bordered completion menu
+ documentation = cmp.config.window.bordered(), -- Bordered documentation window
+ },
+ experimental = {
+ ghost_text = true, -- Show ghost text for inline completion
+ },
+ }
+
+ -- Command-line completion for `/` and `?`
+ cmp.setup.cmdline({ "/", "?" }, {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = {
+ { name = "buffer" },
+ },
+ })
+
+ -- Command-line completion for `:`
+ cmp.setup.cmdline(":", {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = cmp.config.sources({
+ { name = "path" },
+ { name = "cmdline" },
+ }),
+ })
+ end,
+ },
+}