diff --git a/init.lua b/init.lua index d5ae6dc9b2a..b9b9fce8e3d 100644 --- a/init.lua +++ b/init.lua @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.o` @@ -102,7 +102,7 @@ vim.g.have_nerd_font = false vim.o.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.o.relativenumber = true +vim.o.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a' @@ -450,6 +450,11 @@ require('lazy').setup({ builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = false, + layout_config = { + width = 0.7, -- 宽度占屏幕 80%(0~1 之间的百分比,或像素值) + height = 30, -- 高度设置为 20 行 + -- prompt_position = "top", -- 可选:将输入框置于顶部 + }, }) end, { desc = '[/] Fuzzily search in current buffer' }) @@ -614,9 +619,9 @@ require('lazy').setup({ -- You can press `g?` for help in this menu. local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { - 'lua_ls', -- Lua Language server + 'lua-language-server', -- Lua Language server 'stylua', -- Used to format Lua code - -- You can add other tools here that you want Mason to install + 'prettier', -- JS/TS/Markdown 等文件格式化工具 }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } @@ -686,6 +691,7 @@ require('lazy').setup({ end, formatters_by_ft = { lua = { 'stylua' }, + markdown = { 'prettier' }, -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- @@ -824,6 +830,7 @@ require('lazy').setup({ -- - ci' - [C]hange [I]nside [']quote require('mini.ai').setup { n_lines = 500 } + -- TODO: 和跳转插件有冲突 -- Add/delete/replace surroundings (brackets, quotes, etc.) -- -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren @@ -881,12 +888,8 @@ require('lazy').setup({ -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, - -- - -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` - -- Or use telescope! - -- In normal mode type `sh` then write `lazy.nvim-plugin` - -- you can continue same window with `sr` which resumes last telescope search + -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` + { import = 'custom.plugins' }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the diff --git a/lua/custom/plugins/bufferline.lua b/lua/custom/plugins/bufferline.lua new file mode 100644 index 00000000000..af65b271747 --- /dev/null +++ b/lua/custom/plugins/bufferline.lua @@ -0,0 +1,9 @@ +-- tab 页签 +vim.keymap.set('n', 'gb', 'BufferLinePick', { desc = '[G]o to [B]uffer' }) + +return { + 'akinsho/bufferline.nvim', + version = '*', + dependencies = 'nvim-tree/nvim-web-devicons', + opts = {}, +} diff --git a/lua/custom/plugins/chinese-prettier.lua b/lua/custom/plugins/chinese-prettier.lua new file mode 100644 index 00000000000..fb1cc9710ec --- /dev/null +++ b/lua/custom/plugins/chinese-prettier.lua @@ -0,0 +1,4 @@ +-- 中文格式化,中英文之间添加空格 +-- NOTE: 使用 `:PanguAll` 进行格式化 +return { 'hotoo/pangu.vim', ft = { 'markdown' } } + diff --git a/lua/custom/plugins/diffview.lua b/lua/custom/plugins/diffview.lua new file mode 100644 index 00000000000..2d520d37e9c --- /dev/null +++ b/lua/custom/plugins/diffview.lua @@ -0,0 +1,4 @@ +return { + 'sindrets/diffview.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, +} diff --git a/lua/custom/plugins/file-tree.lua b/lua/custom/plugins/file-tree.lua new file mode 100644 index 00000000000..f37f93e45a8 --- /dev/null +++ b/lua/custom/plugins/file-tree.lua @@ -0,0 +1,16 @@ +-- 文件树 +return { + 'nvim-neo-tree/neo-tree.nvim', + version = '*', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', -- 不严格要求,但推荐 + 'MunifTanjim/nui.nvim', + }, + config = function() + require('neo-tree').setup { close_if_last_window = true } + vim.keymap.set('n', 'tf', ':Neotree toggle', { desc = '[T]oggle [F]ileTree' }) + end, +} + +-- vim: ts=2 sts=2 sw=2 et diff --git a/lua/custom/plugins/gitsigns.lua b/lua/custom/plugins/gitsigns.lua new file mode 100644 index 00000000000..fe7781b0334 --- /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/hardtime.lua b/lua/custom/plugins/hardtime.lua new file mode 100644 index 00000000000..f8f07804c54 --- /dev/null +++ b/lua/custom/plugins/hardtime.lua @@ -0,0 +1,7 @@ +-- 建立良好的指挥工作流程,戒除不良习惯。 +-- 按下 `s` 然后输入需要跳转到的位置的单词 +return { + 'm4xshen/hardtime.nvim', + dependencies = { 'MunifTanjim/nui.nvim' }, + opts = {}, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index be0eb9d8d7a..00000000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} diff --git a/lua/custom/plugins/jump.lua b/lua/custom/plugins/jump.lua new file mode 100644 index 00000000000..202a6e1c2ef --- /dev/null +++ b/lua/custom/plugins/jump.lua @@ -0,0 +1,17 @@ +-- 快速跳转 +-- 按下 `s` 然后输入需要跳转到的位置的单词 +return { + 'folke/flash.nvim', + event = 'VeryLazy', + ---@type Flash.Config + opts = {}, + -- stylua: ignore + keys = { + { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, + { "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, + { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, + { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, + { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, + }, +} + diff --git a/lua/custom/plugins/keymaps.lua b/lua/custom/plugins/keymaps.lua new file mode 100644 index 00000000000..892df9506d4 --- /dev/null +++ b/lua/custom/plugins/keymaps.lua @@ -0,0 +1,6 @@ +-- 使用 Shift + j/k 代替 Ctrl + d/u + +vim.keymap.set('n', '', '') +vim.keymap.set('n', '', '') + +return {} diff --git a/lua/custom/plugins/markdown-preview.lua b/lua/custom/plugins/markdown-preview.lua new file mode 100644 index 00000000000..4a3290846f8 --- /dev/null +++ b/lua/custom/plugins/markdown-preview.lua @@ -0,0 +1,11 @@ +-- Markdown 预览 +-- :MarkdownPreview +return { + 'iamcco/markdown-preview.nvim', + build = 'cd app && npm install', + ft = 'markdown', + config = function() + vim.g.mkdp_auto_start = 1 + end, +} + diff --git a/lua/custom/plugins/mini.lua b/lua/custom/plugins/mini.lua new file mode 100644 index 00000000000..7ff88f51e1a --- /dev/null +++ b/lua/custom/plugins/mini.lua @@ -0,0 +1,38 @@ +-- Mini 全家桶 +return { + 'echasnovski/mini.nvim', + config = function() + -- 可视化显示缩进范围 + require('mini.indentscope').setup() + + -- 自动配对 + require('mini.pairs').setup() + + -- 启动界面 + require('mini.starter').setup() + + -- 小地图 + local map = require 'mini.map' + + map.setup { + integrations = { + map.gen_integration.builtin_search(), + map.gen_integration.gitsigns(), + map.gen_integration.diagnostic(), + }, + symbols = { + encode = map.gen_encode_symbols.dot '4x2', + }, + } + + vim.keymap.set('n', 'tm', map.toggle, { desc = '[T]oggle [M]ap' }) + + vim.cmd [[autocmd User MiniStarterOpened + \ lua vim.keymap.set( + \ 'n', + \ '', + \ 'lua MiniStarter.eval_current_item(); MiniMap.open()', + \ { buffer = true } + \ )]] + end, +} diff --git a/lua/custom/plugins/noice.lua b/lua/custom/plugins/noice.lua new file mode 100644 index 00000000000..4e53a0e595c --- /dev/null +++ b/lua/custom/plugins/noice.lua @@ -0,0 +1,18 @@ +-- 更好的消息提示,命令输入框 +-- 取代 messages, cmdline 和 popupmenu +return { + 'folke/noice.nvim', + event = 'VeryLazy', + opts = { + -- add any options here + }, + dependencies = { + -- if you lazy-load any plugin below, make sure to add proper `module="..."` entries + 'MunifTanjim/nui.nvim', + -- OPTIONAL: + -- `nvim-notify` is only needed, if you want to use the notification view. + -- If not available, we use `mini` as the fallback + -- 'rcarriga/nvim-notify', + }, +} + diff --git a/lua/custom/plugins/render-markdown.lua b/lua/custom/plugins/render-markdown.lua new file mode 100644 index 00000000000..36c76da1861 --- /dev/null +++ b/lua/custom/plugins/render-markdown.lua @@ -0,0 +1,15 @@ +-- Markdown 预览 +return { + 'MeanderingProgrammer/render-markdown.nvim', + dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.nvim' }, -- if you use the mini.nvim suite + -- dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.icons' }, -- if you use standalone mini plugins + -- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, -- if you prefer nvim-web-devicons + ---@module 'render-markdown' + ---@type render.md.UserConfig + opts = {}, + config = function() + local rm = require 'render-markdown' + + vim.keymap.set('n', 'tp', rm.toggle, { noremap = true, silent = true, expr = true, desc = '[T]oggle [P]review Markdown' }) + end, +} diff --git a/lua/custom/plugins/statusline.lua b/lua/custom/plugins/statusline.lua new file mode 100644 index 00000000000..14d631702a3 --- /dev/null +++ b/lua/custom/plugins/statusline.lua @@ -0,0 +1,18 @@ +-- 更好状态栏 +return { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + opts = { + options = { + theme = 'palenight', + component_separators = '', + section_separators = { left = '', right = '' }, + }, + sections = { + lualine_a = { { 'mode', separator = { left = '' }, right_padding = 2 } }, + lualine_z = { + { 'location', separator = { right = '' }, left_padding = 2 }, + }, + }, + }, +} diff --git a/lua/custom/plugins/terminal.lua b/lua/custom/plugins/terminal.lua new file mode 100644 index 00000000000..178782cd53c --- /dev/null +++ b/lua/custom/plugins/terminal.lua @@ -0,0 +1,20 @@ +local powershell_options = { + -- shell = vim.fn.executable 'pwsh' == 1 and 'pwsh' or 'powershell', + -- shellcmdflag = '-NoLogo -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();$PSDefaultParameterValues[', + -- shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode', + -- shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode', + -- shellquote = '', + -- shellxquote = '', + shell = vim.fn.executable 'pwsh' == 1 and 'pwsh' or 'powershell', + shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;', + shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait', + shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode', + shellquote = '', + shellxquote = '', +} + +for option, value in pairs(powershell_options) do + vim.opt[option] = value +end + +return {} diff --git a/lua/custom/plugins/text-replace.lua b/lua/custom/plugins/text-replace.lua new file mode 100644 index 00000000000..c81db5a3375 --- /dev/null +++ b/lua/custom/plugins/text-replace.lua @@ -0,0 +1,9 @@ +-- 文本替换 +-- :Spectre +return { + 'nvim-pack/nvim-spectre', + event = 'BufRead', + opts = {}, +} + +-- vim: ts=2 sts=2 sw=2 et diff --git a/lua/custom/plugins/translation.lua b/lua/custom/plugins/translation.lua new file mode 100644 index 00000000000..f4354f0ca23 --- /dev/null +++ b/lua/custom/plugins/translation.lua @@ -0,0 +1,23 @@ +-- 翻译 +-- 选中内容后,leader [T]ranslate +-- NOTE: 弹出窗中 `g?` 查看操作帮助 +return { + 'potamides/pantran.nvim', + config = function() + local pantran = require 'pantran' + pantran.setup { + default_engine = 'google', + engines = { + google = { + fallback = { + default_source = 'auto', + default_target = 'zh', + }, + }, + }, + } + + vim.keymap.set('x', 't', pantran.motion_translate, { noremap = true, silent = true, expr = true, desc = '[T]ranslate' }) + end, +} + diff --git a/lua/kickstart/plugins/indent_line.lua b/lua/kickstart/plugins/indent_line.lua index ed7f269399f..9f579cb8d51 100644 --- a/lua/kickstart/plugins/indent_line.lua +++ b/lua/kickstart/plugins/indent_line.lua @@ -1,3 +1,4 @@ +-- 显示缩进线 return { { -- Add indentation guides even on blank lines 'lukas-reineke/indent-blankline.nvim', diff --git a/lua/kickstart/plugins/neo-tree.lua b/lua/kickstart/plugins/neo-tree.lua index c7067891df0..c30d4bcc481 100644 --- a/lua/kickstart/plugins/neo-tree.lua +++ b/lua/kickstart/plugins/neo-tree.lua @@ -1,13 +1,17 @@ -- Neo-tree is a Neovim plugin to browse the file system +-- Neo-Tree 是一个浏览文件系统的 Neovim 插件 -- https://github.com/nvim-neo-tree/neo-tree.nvim +-- leader [T]oggle [F]ileTree : 开关文件树 +-- 文件树内部 `?` 查看帮助 + return { 'nvim-neo-tree/neo-tree.nvim', version = '*', dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended - 'MunifTanjim/nui.nvim', + 'nvim-lua/plenary.nvim', -- 一个 Neovim 的 Lua 工具库,NeoTree 依赖它提供一些实用函数。 + 'nvim-tree/nvim-web-devicons', -- 为文件和文件夹提供图标,虽然不是必需的,但推荐安装以增强界面。 + 'MunifTanjim/nui.nvim', -- 一个用于构建用户界面的 Lua 库,NeoTree 用它来创建其界面组件。 }, lazy = false, keys = {