From 540268d618627079c9b958a955b586e1888b46a8 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Tue, 10 Aug 2021 23:15:04 +0200 Subject: Major refactor of nvim --- .config/nvim/lua/core/compe.lua | 50 ++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to '.config/nvim/lua/core/compe.lua') 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 = { + -- [""] = { 'pumvisible() ? "" : ""', { silent = true, noremap = true, expr = true } }, + -- [""] = { 'pumvisible() ? "" : ""', { silent = true, noremap = true, expr = true } }, + [""] = { "compe#complete()", { silent = true, noremap = true, expr = true } }, + [""] = { "compe#close('')", { silent = true, noremap = true, expr = true } }, + [""] = { "compe#scroll({ 'delta': +4 })", { silent = true, noremap = true, expr = true } }, + [""] = { "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 "" - elseif vim.fn.call("vsnip#available", { 1 }) == 1 then - return t "(vsnip-expand-or-jump)" + elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then + return t "(vsnip-jump-next)" elseif check_back_space() then return t "" else - return vim.fn["compe#complete"]() + -- return vim.fn["compe#complete"]() -- < use this if you want to always offer completion + return t "" 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", "", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) - - vim.api.nvim_set_keymap("i", "", "compe#complete()", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#confirm('')", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#close('')", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true }) end return M -- cgit v1.2.3-70-g09d2