From 7af0657a6eef033c4842476239be044fc464ef14 Mon Sep 17 00:00:00 2001 From: QQ <1770362456@qq.com> Date: Fri, 24 Feb 2023 22:16:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bimchange?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init.lua | 2 +- lua/Plugin/Imchange.lua | 14 +++++++++++ lua/Plugin/coc.lua | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 4b1e909..069cf45 100644 --- a/init.lua +++ b/init.lua @@ -5,6 +5,6 @@ require('core.filetype') require('Plugin.coc') require('Plugin.lualine') -require('Plugin.Imchange') require('Plugin.treesitter') require('Plugin.hlchunk') +require('Plugin.Imchange') diff --git a/lua/Plugin/Imchange.lua b/lua/Plugin/Imchange.lua index c4191f1..2cd78b1 100644 --- a/lua/Plugin/Imchange.lua +++ b/lua/Plugin/Imchange.lua @@ -1,3 +1,7 @@ +if package.config:sub(1,1) == "\\" then + return +end + local G, im = require("G"), "keyboard-us" function InsertLeave() @@ -13,6 +17,13 @@ function InsertEnter() end end +function Is_fcitx5_installed() + local cmd = "fcitx5 -v" + local status = os.execute(cmd) + return (status == 0) +end + +if Is_fcitx5_installed() then G.api.nvim_create_autocmd( {"InsertLeave"}, { pattern = "*", @@ -26,3 +37,6 @@ G.api.nvim_create_autocmd( callback = InsertEnter } ) +end + + diff --git a/lua/Plugin/coc.lua b/lua/Plugin/coc.lua index 43cde1c..2e24601 100644 --- a/lua/Plugin/coc.lua +++ b/lua/Plugin/coc.lua @@ -84,3 +84,54 @@ keyset("n", "tr", "(coc-translator-r)") keyset("v", "tr", "(coc-translator-rv)") keyset("n", "ol", ":CocOutline") + +-- Highlight the symbol and its references on a CursorHold event(cursor is idle) +G.api.nvim_create_augroup("CocGroup", {}) +G.api.nvim_create_autocmd("CursorHold", { + group = "CocGroup", + command = "silent call CocActionAsync('highlight')", + desc = "Highlight symbol under cursor on CursorHold" +}) + +-- Setup formatexpr specified filetype(s) +G.api.nvim_create_autocmd("FileType", { + group = "CocGroup", + pattern = "typescript,json", + command = "setl formatexpr=CocAction('formatSelected')", + desc = "Setup formatexpr specified filetype(s)." +}) + +-- Update signature help on jump placeholder +G.api.nvim_create_autocmd("User", { + group = "CocGroup", + pattern = "CocJumpPlaceholder", + command = "call CocActionAsync('showSignatureHelp')", + desc = "Update signature help on jump placeholder" +}) + +-- Remap and to scroll float windows/popups +---@diagnostic disable-next-line: redefined-local +local opts = {silent = true, nowait = true, expr = true} +keyset("n", "", 'coc#float#has_scroll() ? coc#float#scroll(1) : ""', opts) +keyset("n", "", 'coc#float#has_scroll() ? coc#float#scroll(0) : ""', opts) +keyset("i", "", + 'coc#float#has_scroll() ? "=coc#float#scroll(1)" : ""', opts) +keyset("i", "", + 'coc#float#has_scroll() ? "=coc#float#scroll(0)" : ""', opts) +keyset("v", "", 'coc#float#has_scroll() ? coc#float#scroll(1) : ""', opts) +keyset("v", "", 'coc#float#has_scroll() ? coc#float#scroll(0) : ""', opts) + +-- Add `:Format` command to format current buffer +G.api.nvim_create_user_command("Format", "call CocAction('format')", {}) + +-- " Add `:Fold` command to fold current buffer +G.api.nvim_create_user_command("Fold", "call CocAction('fold', )", {nargs = '?'}) + +-- Add `:OR` command for organize imports of the current buffer +G.api.nvim_create_user_command("OR", "call CocActionAsync('runCommand', 'editor.action.organizeImport')", {}) + +-- Add (Neo)Vim's native statusline support +-- NOTE: Please see `:h coc-status` for integrations with external plugins that +-- provide custom statusline: lightline.vim, vim-airline +G.opt.statusline:prepend("%{coc#status()}%{get(b:,'coc_current_function','')}") +