summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortriethyl <triethylammonium@pm.me>2025-08-07 14:16:14 -0400
committertriethyl <triethylammonium@pm.me>2025-08-07 14:16:14 -0400
commitb2a806b5078391dd8f9ee94fdc8be5c3b0271187 (patch)
tree130e058913a63b07493c0ad349c7c0d743855c57
parentc37d47e19df8559f5b7dcd40aca832623a6fa9b0 (diff)
neovim: added completion
-rw-r--r--pkgs/custom-neovim/config/init.lua1
-rw-r--r--pkgs/custom-neovim/config/lua/completion.lua89
-rw-r--r--pkgs/custom-neovim/default.nix2
3 files changed, 91 insertions, 1 deletions
diff --git a/pkgs/custom-neovim/config/init.lua b/pkgs/custom-neovim/config/init.lua
index 857aa37..7fa0669 100644
--- a/pkgs/custom-neovim/config/init.lua
+++ b/pkgs/custom-neovim/config/init.lua
@@ -10,6 +10,7 @@ require("neovide")
require("mappings")
require("statusline")
require("lsp")
+require("completion")
-- Require plugin configs.
-- UI Plugins:
diff --git a/pkgs/custom-neovim/config/lua/completion.lua b/pkgs/custom-neovim/config/lua/completion.lua
new file mode 100644
index 0000000..b690293
--- /dev/null
+++ b/pkgs/custom-neovim/config/lua/completion.lua
@@ -0,0 +1,89 @@
+vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
+
+require('luasnip.loaders.from_vscode').lazy_load()
+
+local cmp = require('cmp')
+local luasnip = require('luasnip')
+
+local select_opts = {behavior = cmp.SelectBehavior.Select}
+
+cmp.setup({
+ snippet = {
+ expand = function(args)
+ luasnip.lsp_expand(args.body)
+ end
+ },
+ sources = {
+ {name = 'path'},
+ {name = 'nvim_lsp', keyword_length = 1},
+ {name = 'buffer', keyword_length = 3},
+ {name = 'luasnip', keyword_length = 2},
+ },
+ window = {
+ documentation = cmp.config.window.bordered()
+ },
+ formatting = {
+ fields = {'menu', 'abbr', 'kind'},
+ format = function(entry, item)
+ local menu_icon = {
+ nvim_lsp = 'λ',
+ luasnip = '⋗',
+ buffer = 'Ω',
+ path = '🖫',
+ }
+
+ item.menu = menu_icon[entry.source.name]
+ return item
+ end,
+ },
+ mapping = {
+ ['<Up>'] = cmp.mapping.select_prev_item(select_opts),
+ ['<Down>'] = cmp.mapping.select_next_item(select_opts),
+
+ ['<C-p>'] = cmp.mapping.select_prev_item(select_opts),
+ ['<C-n>'] = cmp.mapping.select_next_item(select_opts),
+
+ ['<C-u>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-d>'] = cmp.mapping.scroll_docs(4),
+
+ ['<C-e>'] = cmp.mapping.abort(),
+ ['<C-y>'] = cmp.mapping.confirm({select = true}),
+ ['<CR>'] = cmp.mapping.confirm({select = false}),
+
+ ['<C-f>'] = cmp.mapping(function(fallback)
+ if luasnip.jumpable(1) then
+ luasnip.jump(1)
+ else
+ fallback()
+ end
+ end, {'i', 's'}),
+
+ ['<C-b>'] = cmp.mapping(function(fallback)
+ if luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ else
+ fallback()
+ end
+ end, {'i', 's'}),
+
+ ['<Tab>'] = cmp.mapping(function(fallback)
+ local col = vim.fn.col('.') - 1
+
+ if cmp.visible() then
+ cmp.select_next_item(select_opts)
+ elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
+ fallback()
+ else
+ cmp.complete()
+ end
+ end, {'i', 's'}),
+
+ ['<S-Tab>'] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item(select_opts)
+ else
+ fallback()
+ end
+ end, {'i', 's'}),
+ },
+})
diff --git a/pkgs/custom-neovim/default.nix b/pkgs/custom-neovim/default.nix
index 47633a7..10ec541 100644
--- a/pkgs/custom-neovim/default.nix
+++ b/pkgs/custom-neovim/default.nix
@@ -23,7 +23,7 @@ in
nvim-ts-autotag
gitsigns-nvim
- # Completion Sources
+ # Completion
nvim-cmp
cmp-buffer
cmp-path