summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/core/compe.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-10 23:15:04 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-08-10 23:15:04 +0200
commit540268d618627079c9b958a955b586e1888b46a8 (patch)
tree1a22a5feb457135178b9d4fe8b6c1755f5ca66bc /.config/nvim/lua/core/compe.lua
parente79bd3273f58ba38e8fcd716090b89326791afbb (diff)
Major refactor of nvim
Diffstat (limited to '.config/nvim/lua/core/compe.lua')
-rw-r--r--.config/nvim/lua/core/compe.lua50
1 files changed, 37 insertions, 13 deletions
diff --git a/.config/nvim/lua/core/compe.lua b/.config/nvim/lua/core/compe.lua
index c8152ad..3291918 100644
--- a/.config/nvim/lua/core/compe.lua
+++ b/.config/nvim/lua/core/compe.lua
@@ -1,6 +1,7 @@
local M = {}
+local Log = require "core.log"
M.config = function()
- O.completion = {
+ options.builtin.compe = {
enabled = true,
autocomplete = true,
debug = false,
@@ -12,7 +13,15 @@ M.config = function()
max_abbr_width = 100,
max_kind_width = 100,
max_menu_width = 100,
- documentation = true,
+ documentation = {
+ border = "single",
+ winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder",
+ max_width = 120,
+ min_width = 60,
+ max_height = math.floor(vim.o.lines * 0.3),
+ min_height = 1,
+ },
+ -- documentation = true,
source = {
path = { kind = "  (Path)" },
@@ -30,18 +39,35 @@ M.config = function()
emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } },
-- for emoji press : (idk if that in compe tho)
},
+
+ keymap = {
+ values = {
+ insert_mode = {
+ -- ["<Tab>"] = { 'pumvisible() ? "<C-n>" : "<Tab>"', { silent = true, noremap = true, expr = true } },
+ -- ["<S-Tab>"] = { 'pumvisible() ? "<C-p>" : "<S-Tab>"', { silent = true, noremap = true, expr = true } },
+ ["<C-Space>"] = { "compe#complete()", { silent = true, noremap = true, expr = true } },
+ ["<C-e>"] = { "compe#close('<C-e>')", { silent = true, noremap = true, expr = true } },
+ ["<C-f>"] = { "compe#scroll({ 'delta': +4 })", { silent = true, noremap = true, expr = true } },
+ ["<C-d>"] = { "compe#scroll({ 'delta': -4 })", { silent = true, noremap = true, expr = true } },
+ },
+ },
+ opts = {
+ insert_mode = { noremap = true, silent = true, expr = true },
+ },
+ },
}
end
M.setup = function()
- vim.g.vsnip_snippet_dir = O.vsnip_dir
+ vim.g.vsnip_snippet_dir = options.vsnip_dir
local status_ok, compe = pcall(require, "compe")
if not status_ok then
+ Log:get_default().error "Failed to load compe"
return
end
- compe.setup(O.completion)
+ compe.setup(options.builtin.compe)
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
@@ -62,12 +88,13 @@ M.setup = function()
_G.tab_complete = function()
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 vim.fn.call("vsnip#jumpable", { 1 }) == 1 then
+ return t "<Plug>(vsnip-jump-next)"
elseif check_back_space() then
return t "<Tab>"
else
- return vim.fn["compe#complete"]()
+ -- return vim.fn["compe#complete"]() -- < use this if you want <tab> to always offer completion
+ return t "<Tab>"
end
end
@@ -81,16 +108,13 @@ M.setup = function()
end
end
+ local keymap = require "keymappings"
+ keymap.load(options.builtin.compe.keymap.values, options.builtin.compe.keymap.opts)
+
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true })
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 })
end
return M