diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 9199b9d..1694204 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -13,7 +13,7 @@ require("statusline") -- ./lua/statusline.lua require("polyjuice") -- ~/.local/src/polyjuice/lua/polyjuice.lua -- auto complete -require("plugin.compe") -- ./lua/plugin/compe.lua +require("plugin.cmp") -- ./lua/plugin/cmp.lua -- treesitter require("plugin.treesitter") -- ./lua/plugin/treesitter.lua diff --git a/.config/nvim/lua/plugin/cmp.lua b/.config/nvim/lua/plugin/cmp.lua new file mode 100644 index 0000000..deebb51 --- /dev/null +++ b/.config/nvim/lua/plugin/cmp.lua @@ -0,0 +1,81 @@ +-- Author : swytch +-- Created : Saturday Sept. 11, 2021 22:12:33 CET +-- License : GPLv3 +-- Description : cmp plugin config file + +local cmp = require("cmp") +local luasnip = require("luasnip") + +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local check_backspace = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and + vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]: + sub(col, col):match('%s') == nil +end + +cmp.setup { + completion = { + autocomplete = false + }, + sources = { + { name = "path" }, + { name = "buffer" }, + { name = "nvim_lsp" }, + { name = "nvim_lua" }, + { name = "treesitter" }, + { name = "calc" }, + { name = "spell" }, + }, + formatting = { + format = function(entry, vim_item) + vim_item.menu = ({ + nvim_lsp = "[lsp]", + nvim_lua = "[nvim]", + path = "[path]", + buffer = "[buff]", + calc = "[calc]", + spell = "[spel]", + treesitter = "[tree]", + })[entry.source.name] + return vim_item + end, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(t "", "n") + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(t "", "n") + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + } +} diff --git a/.config/nvim/lua/plugin/compe.lua b/.config/nvim/lua/plugin/compe.lua deleted file mode 100644 index 0436288..0000000 --- a/.config/nvim/lua/plugin/compe.lua +++ /dev/null @@ -1,73 +0,0 @@ --- Author : swytch --- Created : Tuesday Mar 18, 2021 23:12:25 CET --- License : GPLv3 --- Description : compe plugin config file - -require("compe").setup { - enabled = true; - autocomplete = false; - debug = false; - min_length = 1; - preselect = "enable"; - throttle_time = 80; - source_timeout = 200; - incomplete_delay = 400; - max_abbr_width = 100; - max_kind_width = 10; - max_menu_width = 100; - documentation = true; - - source = { - path = {menu = " [path]"}, - buffer = {menu = " [buff]"}, - calc = {menu = " [calc]"}, - -- vsnip = {menu = " [snip]"}, - nvim_lsp = {menu = " [LSP]"}, - nvim_lua = {menu = " [nvim]"}, - spell = {menu = " [spel]"}, - tags = false, - treesitter = {menu = " [tree]"}, - }; -} - -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) -end - -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() - if vim.fn.pumvisible() == 1 then - return t "" --- elseif vim.fn.call("vsnip#available", {1}) == 1 then --- return t "(vsnip-expand-or-jump)" - elseif check_back_space() then - return t "" - else - return vim.fn['compe#complete']() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" --- elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then --- return t "(vsnip-jump-prev)" - else - return t "" - end -end - -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}) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 59e78ec..e002111 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -55,7 +55,19 @@ return require("packer").startup(function() } -- auto completion - use "hrsh7th/nvim-compe" + use { + "hrsh7th/nvim-cmp", + requires = { + "L3MON4D3/LuaSnip", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-calc", + "ray-x/cmp-treesitter", + "f3fora/cmp-spell" + } + } -- display colors directly in editor use { @@ -63,4 +75,6 @@ return require("packer").startup(function() cmd = "ColorizerToggle" } + -- ens + use "whonore/Coqtail" end) diff --git a/.local/src/polyjuice b/.local/src/polyjuice index 800a770..4136059 160000 --- a/.local/src/polyjuice +++ b/.local/src/polyjuice @@ -1 +1 @@ -Subproject commit 800a770838d28e2430b85b28d1c907ae55cae782 +Subproject commit 41360594fd669ec9f4d09e552c77764dde302c3b