LunarVim/lua/lv-compe/init.lua

101 lines
3 KiB
Lua
Raw Normal View History

--if not package.loaded['compe'] then
-- return
-- end
2021-06-28 04:11:33 +02:00
local M = {}
2021-03-15 16:54:53 +01:00
vim.g.vsnip_snippet_dir = O.vnsip_dir
2021-06-28 04:11:33 +02:00
M.config = function()
2021-07-04 16:45:38 +02:00
opt = {
2021-03-27 06:59:28 +01:00
enabled = O.auto_complete,
2021-03-20 07:32:49 +01:00
autocomplete = true,
debug = false,
min_length = 1,
preselect = 'enable',
throttle_time = 80,
source_timeout = 200,
incomplete_delay = 400,
max_abbr_width = 100,
max_kind_width = 100,
max_menu_width = 100,
documentation = true,
2021-03-10 05:55:11 +01:00
2021-03-20 07:32:49 +01:00
source = {
2021-04-27 07:17:29 +02:00
path = {kind = "  (Path)"},
buffer = {kind = "  (Buffer)"},
calc = {kind = "  (Calc)"},
vsnip = {kind = "  (Snippet)"},
nvim_lsp = {kind = "  (LSP)"},
2021-03-27 09:06:14 +01:00
-- nvim_lua = {kind = "  "},
nvim_lua = false,
2021-04-27 07:17:29 +02:00
spell = {kind = "  (Spell)"},
2021-03-20 07:32:49 +01:00
tags = false,
2021-03-30 21:15:38 +02:00
vim_dadbod_completion = true,
2021-03-26 00:58:40 +01:00
-- snippets_nvim = {kind = "  "},
-- ultisnips = {kind = "  "},
2021-03-26 18:50:38 +01:00
-- treesitter = {kind = "  "},
2021-04-27 07:17:29 +02:00
emoji = {kind = " ﲃ (Emoji)", filetypes={"markdown", "text"}}
2021-03-20 07:32:49 +01:00
-- for emoji press : (idk if that in compe tho)
}
2021-03-10 05:55:11 +01:00
}
2021-07-04 16:45:38 +02:00
if O.plugin.tabnine.active then
opt.source.tabnine = {kind = "", priority=200, max_reslts=6}
end
require'compe'.setup(opt)
2021-03-10 05:55:11 +01:00
local t = function(str)
2021-04-27 07:17:29 +02:00
return vim.api.nvim_replace_termcodes(str, true, true, true)
2021-03-10 05:55:11 +01:00
end
2021-03-14 20:10:28 +01:00
local check_back_space = function()
local col = vim.fn.col('.') - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
2021-04-27 07:17:29 +02:00
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif vim.fn.call("vsnip#available", {1}) == 1 then
return t "<Plug>(vsnip-expand-or-jump)"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
2021-03-14 20:10:28 +01:00
end
2021-03-10 05:55:11 +01:00
_G.s_tab_complete = function()
2021-04-27 07:17:29 +02:00
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
return t "<S-Tab>"
end
2021-03-10 05:55:11 +01:00
end
2021-03-14 20:10:28 +01:00
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
2021-03-10 05:55:11 +01:00
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", {noremap = true, silent = true, expr = true})
vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", {noremap = true, silent = true, expr = true})
vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", {noremap = true, silent = true, expr = true})
vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", {noremap = true, silent = true, expr = true})
vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", {noremap = true, silent = true, expr = true})
2021-06-28 04:11:33 +02:00
end
return M