From 5c87ac928872047569d03e4df8af9bb729aed9cc Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Wed, 1 Sep 2021 00:15:10 +0200 Subject: [PATCH] update nvim config --- .config/nvim/lua/maps.lua | 44 +++++++++++++++++++++++++++-- .config/nvim/lua/pluginconf/coc.lua | 24 +++++++++++++--- .config/nvim/lua/plugins.lua | 1 - 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/.config/nvim/lua/maps.lua b/.config/nvim/lua/maps.lua index 5e325db..c31e686 100644 --- a/.config/nvim/lua/maps.lua +++ b/.config/nvim/lua/maps.lua @@ -1,4 +1,41 @@ -local map = vim.api.nvim_set_keymap +map = vim.api.nvim_set_keymap + +function escape_keycode(keycode) + return vim.api.nvim_replace_termcodes(keycode, true, true, true) +end + +local function check_back_space() + local col = vim.fn.col(".") - 1 + return col <= 0 or vim.fn.getline("."):sub(col, col):match("%s") +end + +function tab_completion() + if vim.fn.pumvisible() > 0 then + return escape_keycode("") + end + + if check_back_space() then + return escape_keycode("") + end + + return vim.fn["coc#refresh"]() +end + +function shift_tab_completion() + if vim.fn.pumvisible() > 0 then + return escape_keycode("") + else + return escape_keycode("") + end +end + +function cr_completion() + if vim.fn.pumvisible() > 0 then + return vim.fn["coc#_select_confirm"]() + else + return escape_keycode("") + end +end -- Getting stuck in ~~vim~~ terminal map("t", "", "", {}) @@ -17,6 +54,10 @@ map("n", "*y", "\"*y", { noremap = true }) map("n", "*p", "\"*p", { noremap = true }) map("n", "*d", "\"*d", { noremap = true }) +map("i", "", "v:lua.tab_completion()", { expr = true }) +map("i", "", "v:lua.shift_tab_completion()", { expr = true }) +map("i", "", "v:lua.cr_completion()", { expr = true }) + -- symbol renaming map("n", "-n", "(coc-rename)", { silent = true }) -- apply AutoFix to problem on current line @@ -47,4 +88,3 @@ map("n", "-d", "(coc-diagnostic-next)", { silent = true }) -- Use -o to show outline map("n", "-o", ":CocList outline", { silent = true }) - diff --git a/.config/nvim/lua/pluginconf/coc.lua b/.config/nvim/lua/pluginconf/coc.lua index 1fffefd..7fef761 100644 --- a/.config/nvim/lua/pluginconf/coc.lua +++ b/.config/nvim/lua/pluginconf/coc.lua @@ -1,3 +1,5 @@ +coc = {} + vim.g.coc_global_extensions = { "coc-clangd", "coc-fish", @@ -18,16 +20,30 @@ local function check_back_space() return col <= 0 or vim.fn.getline("."):sub(col, col):match("%s") end -function tab_completion() +function coc.tab_completion() if vim.fn.pumvisible() > 0 then - return vim.api.nvim_replace_termcodes("", true, true, true) + return escape_keycode("") end if check_back_space() then - return vim.api.nvim_replace_termcodes("", true, true, true) + return escape_keycode("") end return vim.fn["coc#refresh"]() end -vim.api.nvim_set_keymap("i", "", "v:lua.tab_completion()", { expr = true, noremap = false }) +function coc.shift_tab_completion() + if vim.fn.pumvisible() > 0 then + return escape_keycode("") + else + return escape_keycode("") + end +end + +function coc.cr_completion() + if vim.fn.pumvisible() > 0 then + return vim.fn["coc#_select_confirm"]() + else + return escape_keycode([[\u\\=coc#on_enter()\]]) + end +end diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index c2397be..08c2a0e 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -23,7 +23,6 @@ return require("packer").startup(function(use) "jiangmiao/auto-pairs", config = pconf("autopairs") } - use "tpope/vim-endwise" use "vimwiki/vimwiki" use { "glacambre/firenvim",