Skip to content

Commit

Permalink
Add autocmd for completion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JafarAbdi committed Jun 21, 2024
1 parent 4ca2ed8 commit 099e18f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion neovim/.config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,32 @@ vim.api.nvim_create_autocmd("TermOpen", {
group = general_group,
})

local completion = {
pattern = "\\k",
}

vim.api.nvim_create_autocmd("InsertCharPre", {
callback = function()
if tonumber(vim.fn.pumvisible()) ~= 0 then
return
end
local function feedkeys(keys)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), "n", true)
end
if vim.fn.match(vim.v.char, completion.pattern) >= 0 then
if
vim.iter(vim.lsp.get_clients({ bufnr = 0 })):any(function(client)
return client.supports_method(vim.lsp.protocol.Methods.textDocument_completion)
end)
then
vim.lsp.completion.trigger()
else
feedkeys("<C-n>")
end
end
end,
group = general_group,
})
vim.api.nvim_create_autocmd("FocusGained", { command = "checktime", group = general_group })
vim.api.nvim_create_autocmd("LspDetach", {
callback = function(args)
Expand All @@ -389,7 +415,7 @@ vim.api.nvim_create_autocmd("LspDetach", {
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
vim.lsp.completion.enable(true, args.data.client_id, args.buf, { autotrigger = true })
vim.keymap.set("i", "<c-n>", function()
vim.keymap.set("i", "<c-space>", function()
vim.lsp.completion.trigger()
end, { buffer = args.buf })
vim.keymap.set("i", "<CR>", function()
Expand Down Expand Up @@ -1108,6 +1134,7 @@ vim.filetype.add({
})

vim.cmd.colorscheme("retrobox")
vim.api.nvim_set_hl(0, "SpellBad", { sp = "red", undercurl = true })
---------------
--- Keymaps ---
---------------
Expand Down

0 comments on commit 099e18f

Please sign in to comment.