From c3a1663bdb471601d88efba7c3cb0b83e6d1a9e5 Mon Sep 17 00:00:00 2001 From: caprain Date: Wed, 15 Apr 2026 16:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0git=20signs=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/pack/configs/gitsigns.lua | 37 +++++++++++++++++++++++++++++++++++ lua/pack/configs/peek.lua | 2 +- lua/pack/plugins.lua | 32 ++++++++++++++++-------------- nvim-pack-lock.json | 4 ++++ snippets/lua.json | 2 +- 5 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 lua/pack/configs/gitsigns.lua diff --git a/lua/pack/configs/gitsigns.lua b/lua/pack/configs/gitsigns.lua new file mode 100644 index 0000000..8183059 --- /dev/null +++ b/lua/pack/configs/gitsigns.lua @@ -0,0 +1,37 @@ +-- === git signs === +if vim.g.vscode then return end + +local P = { + name = "gitsigns.nvim", + build_cmd = ":TSUpdate", +} + +-- 注册构建监听器 +PackUtils.setup_listener(P.name, P.build_cmd) + +-- 懒加载触发器 +vim.api.nvim_create_autocmd({ + "UIEnter", -- vim.schedule(function() +}, { + callback = function() + vim.schedule(function() + PackUtils.load(P, function() + require('gitsigns').setup { + on_attach = function() + local gitsigns = require('gitsigns') + local map = require("core.keymap") + -- Navigation + map:lua('t=', function() + gitsigns.nav_hunk('next') + end) + map:lua('t-', function() + gitsigns.nav_hunk('prev') + end) + -- show diff + map:lua('hd', gitsigns.diffthis) + end + } + end) + end) + end +}) diff --git a/lua/pack/configs/peek.lua b/lua/pack/configs/peek.lua index 0ef3c87..0a6dfc9 100644 --- a/lua/pack/configs/peek.lua +++ b/lua/pack/configs/peek.lua @@ -23,7 +23,7 @@ end, { desc = "Lazy load and open Peek" }) vim.api.nvim_create_user_command("PeekClose", function() -- 如果插件没加载,Close 命令通常不需要做任何事,或者也触发加载 - if PackUtils.is_initialized[P.name] then + if PackUtils.plugin_loaded[P.name] then require("peek").close() end end, { desc = "Close Peek" }) diff --git a/lua/pack/plugins.lua b/lua/pack/plugins.lua index 62c2235..58e8b03 100644 --- a/lua/pack/plugins.lua +++ b/lua/pack/plugins.lua @@ -19,29 +19,31 @@ local specs = { -- treesitter.lua 需要安装tree-sitter-cli工具包 'https://github.com/nvim-treesitter/nvim-treesitter', -- indentblankline.lua 彩虹缩进 - "https://github.com/lukas-reineke/indent-blankline.nvim", + 'https://github.com/lukas-reineke/indent-blankline.nvim', + -- gitsigns.lua 突出增、删、改过的行 + 'https://github.com/lewis6991/gitsigns.nvim', -- ufo.lua 折叠插件 - "https://github.com/kevinhwang91/nvim-ufo", - "https://github.com/kevinhwang91/promise-async", + 'https://github.com/kevinhwang91/nvim-ufo', + 'https://github.com/kevinhwang91/promise-async', -- stickscroll.lua 代码函数名称浏览时固定 - "https://github.com/nvim-treesitter/nvim-treesitter-context", + 'https://github.com/nvim-treesitter/nvim-treesitter-context', -- bufferline.lua 顶部状态栏 'https://github.com/akinsho/bufferline.nvim', -- lualine.lua 底部状态栏 - "https://github.com/nvim-lualine/lualine.nvim", + 'https://github.com/nvim-lualine/lualine.nvim', -- outline.lua 大纲、函数变量结构 - "https://github.com/hedyhli/outline.nvim", + 'https://github.com/hedyhli/outline.nvim', -- noice.lua 取代消息、命令行和弹出菜单的 UI - "https://github.com/folke/noice.nvim", - "https://github.com/MunifTanjim/nui.nvim", + 'https://github.com/folke/noice.nvim', + 'https://github.com/MunifTanjim/nui.nvim', -- snacks.lua 图片预览、lazygit、lsp_references模糊查找 - "https://github.com/folke/snacks.nvim", + 'https://github.com/folke/snacks.nvim', -- mini.lua 各种对字符的surround包裹{} [] '' - "https://github.com/echasnovski/mini.nvim", + 'https://github.com/echasnovski/mini.nvim', -- autopairs.lua 对字符自动补全另一半 - "https://github.com/windwp/nvim-autopairs", + 'https://github.com/windwp/nvim-autopairs', -- tv.lua 模糊查找television - "https://github.com/alexpasmantier/tv.nvim", + 'https://github.com/alexpasmantier/tv.nvim', -- coderunner.lua 运行代码 'https://github.com/CRAG666/code_runner.nvim', -- peek.lua 预览markdown @@ -49,11 +51,11 @@ local specs = { -- yazi.lua 文件管理器 'https://github.com/mikavilpas/yazi.nvim', -- translate.lua 快捷键翻译 - "https://github.com/uga-rosa/translate.nvim", + 'https://github.com/uga-rosa/translate.nvim', -- sudo权限保存文件 - "https://github.com/lambdalisue/vim-suda", + 'https://github.com/lambdalisue/vim-suda', -- 查看可用键位 - "https://github.com/folke/which-key.nvim", + 'https://github.com/folke/which-key.nvim', } -- 禁用插件:不会加载,不会下载(如果是新添加的),已在硬盘上不会被删除 local disabled = { diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json index 1d8eccf..6ae0fd8 100644 --- a/nvim-pack-lock.json +++ b/nvim-pack-lock.json @@ -20,6 +20,10 @@ "rev": "6cd7280adead7f586db6fccbd15d2cac7e2188b9", "src": "https://github.com/rafamadriz/friendly-snippets" }, + "gitsigns.nvim": { + "rev": "8d82c240f190fc33723d48c308ccc1ed8baad69d", + "src": "https://github.com/lewis6991/gitsigns.nvim" + }, "indent-blankline.nvim": { "rev": "d28a3f70721c79e3c5f6693057ae929f3d9c0a03", "src": "https://github.com/lukas-reineke/indent-blankline.nvim" diff --git a/snippets/lua.json b/snippets/lua.json index bc2fff4..f7841ab 100644 --- a/snippets/lua.json +++ b/snippets/lua.json @@ -11,7 +11,7 @@ "github": { "prefix": "github", "body": [ - "\"https:\/\/github.com\/${0}\"," + "'https:\/\/github.com\/${0}'," ], "description": "Github url" },