diff --git a/lua/custom/plugins/chinese-prettier.lua b/lua/custom/plugins/chinese-prettier.lua index 7cbf7721..fb1cc971 100644 --- a/lua/custom/plugins/chinese-prettier.lua +++ b/lua/custom/plugins/chinese-prettier.lua @@ -1,3 +1,4 @@ -- 中文格式化,中英文之间添加空格 --- NOTE: 使用 `:Pangu` 进行格式化 -return { 'hotoo/pangu.vim', ft = { 'markdown' } } \ No newline at end of file +-- NOTE: 使用 `:PanguAll` 进行格式化 +return { 'hotoo/pangu.vim', ft = { 'markdown' } } + diff --git a/lua/custom/plugins/gitsigns.lua b/lua/custom/plugins/gitsigns.lua new file mode 100644 index 00000000..fe7781b0 --- /dev/null +++ b/lua/custom/plugins/gitsigns.lua @@ -0,0 +1,79 @@ +-- Adds git related signs to the gutter, as well as utilities for managing changes +-- 在 Neovim 中显示 Git 相关的符号(比如行变动、删除、添加等),以及提供多种 Git 操作的快捷方式 +-- NOTE: gitsigns is already included in init.lua but contains only the base +-- config. This will add also the recommended keymaps. +-- NOTE: gitsigns 已包含在 init.lua 中,但仅包含基础配置。这还将添加推荐的 keymaps。 + +return { + { + 'lewis6991/gitsigns.nvim', + opts = { + on_attach = function(bufnr) + local gitsigns = require 'gitsigns' + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + -- 跳转到下个更改 + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal { ']c', bang = true } + else + gitsigns.nav_hunk 'next' + end + end, { desc = 'Jump to next git [c]hange' }) + + -- 跳转到上个更改 + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal { '[c', bang = true } + else + gitsigns.nav_hunk 'prev' + end + end, { desc = 'Jump to previous git [c]hange' }) + + -- Actions + -- visual mode + -- 暂存选中更改 + map('v', 'hs', function() + gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'git [s]tage hunk' }) + -- 重置选中更改 + map('v', 'hr', function() + gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'git [r]eset hunk' }) + + -- normal mode + -- 暂存当前更改 + map('n', 'hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) + -- 重置当前更改 + map('n', 'hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) + -- 暂存缓存区更改 + map('n', 'hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) + map('n', 'hu', gitsigns.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' }) + -- 重置缓冲区更改 + map('n', 'hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) + -- 预览当前更改 + map('n', 'hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) + -- 查看某一行的 Git blame 信息 + map('n', 'hb', gitsigns.blame_line, { desc = 'git [b]lame line' }) + -- 查看文件与索引的差异 + map('n', 'hd', gitsigns.diffthis, { desc = 'git [d]iff against index' }) + -- 查看文件与最后提交的差异 + map('n', 'hD', function() + gitsigns.diffthis '@' + end, { desc = 'git [D]iff against last commit' }) + + -- Toggles + -- 切换显示当前行的 blame 信息。 + map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) + -- 切换显示已删除的行。 + map('n', 'tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) + end, + }, + }, +} diff --git a/lua/custom/plugins/jump.lua b/lua/custom/plugins/jump.lua index 3b7199fd..202a6e1c 100644 --- a/lua/custom/plugins/jump.lua +++ b/lua/custom/plugins/jump.lua @@ -1,7 +1,8 @@ -- 快速跳转 +-- 按下 `s` 然后输入需要跳转到的位置的单词 return { - "folke/flash.nvim", - event = "VeryLazy", + 'folke/flash.nvim', + event = 'VeryLazy', ---@type Flash.Config opts = {}, -- stylua: ignore @@ -12,4 +13,5 @@ return { { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, }, -} \ No newline at end of file +} + diff --git a/lua/custom/plugins/markdown-preview.lua b/lua/custom/plugins/markdown-preview.lua index 9056b572..4a329084 100644 --- a/lua/custom/plugins/markdown-preview.lua +++ b/lua/custom/plugins/markdown-preview.lua @@ -1,4 +1,5 @@ -- Markdown 预览 +-- :MarkdownPreview return { 'iamcco/markdown-preview.nvim', build = 'cd app && npm install', @@ -6,4 +7,5 @@ return { config = function() vim.g.mkdp_auto_start = 1 end, -} \ No newline at end of file +} + diff --git a/lua/custom/plugins/noice.lua b/lua/custom/plugins/noice.lua index e677b8d7..4e53a0e5 100644 --- a/lua/custom/plugins/noice.lua +++ b/lua/custom/plugins/noice.lua @@ -1,3 +1,4 @@ +-- 更好的消息提示,命令输入框 -- 取代 messages, cmdline 和 popupmenu return { 'folke/noice.nvim', @@ -13,4 +14,5 @@ return { -- If not available, we use `mini` as the fallback -- 'rcarriga/nvim-notify', }, -} \ No newline at end of file +} + diff --git a/lua/custom/plugins/statusline.lua b/lua/custom/plugins/statusline.lua index 770554a5..14d63170 100644 --- a/lua/custom/plugins/statusline.lua +++ b/lua/custom/plugins/statusline.lua @@ -1,4 +1,4 @@ --- 状态栏 +-- 更好状态栏 return { 'nvim-lualine/lualine.nvim', dependencies = { 'nvim-tree/nvim-web-devicons' }, diff --git a/lua/custom/plugins/text-replace.lua b/lua/custom/plugins/text-replace.lua index e872cf48..c81db5a3 100644 --- a/lua/custom/plugins/text-replace.lua +++ b/lua/custom/plugins/text-replace.lua @@ -1,4 +1,5 @@ -- 文本替换 +-- :Spectre return { 'nvim-pack/nvim-spectre', event = 'BufRead', diff --git a/lua/custom/plugins/translation.lua b/lua/custom/plugins/translation.lua index 6879a694..f4354f0c 100644 --- a/lua/custom/plugins/translation.lua +++ b/lua/custom/plugins/translation.lua @@ -1,4 +1,5 @@ -- 翻译 +-- 选中内容后,leader [T]ranslate -- NOTE: 弹出窗中 `g?` 查看操作帮助 return { 'potamides/pantran.nvim', @@ -18,4 +19,5 @@ return { vim.keymap.set('x', 't', pantran.motion_translate, { noremap = true, silent = true, expr = true, desc = '[T]ranslate' }) end, -} \ No newline at end of file +} +