From 996cfc643b1d768d025430db998295189c8d8ece Mon Sep 17 00:00:00 2001 From: captain Date: Fri, 27 Feb 2026 19:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=88=A0=E4=B8=80=E4=BA=9B=E6=8F=92?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/lazy/plugins/fold.lua | 1 - lua/lazy/plugins/fzf.lua | 12 ++++- lua/lazy/plugins/gemini.lua | 7 --- lua/lazy/plugins/gitstatus.lua | 21 +++++++- lua/lazy/plugins/lspconfig.lua | 81 ++++++++++++++++++++-------- lua/lazy/plugins/markdownpreview.lua | 3 +- lua/lazy/plugins/television.lua | 34 ++++++++++++ lua/lazy/plugins/topbar.lua | 16 ++++-- lua/lazy/plugins/translate.lua | 16 +++--- 9 files changed, 145 insertions(+), 46 deletions(-) delete mode 100644 lua/lazy/plugins/gemini.lua create mode 100644 lua/lazy/plugins/television.lua diff --git a/lua/lazy/plugins/fold.lua b/lua/lazy/plugins/fold.lua index 7f8eeab..f670429 100644 --- a/lua/lazy/plugins/fold.lua +++ b/lua/lazy/plugins/fold.lua @@ -23,7 +23,6 @@ return { -- you can add other fields for setting up lsp server in this table }) end - require("ufo").setup() -- Option 3: treesitter as a main provider instead -- Only depend on `nvim-treesitter/queries/filetype/folds.scm`, -- performance and stability are better than `foldmethod=nvim_treesitter#foldexpr()` diff --git a/lua/lazy/plugins/fzf.lua b/lua/lazy/plugins/fzf.lua index f2975ed..be151c1 100644 --- a/lua/lazy/plugins/fzf.lua +++ b/lua/lazy/plugins/fzf.lua @@ -4,11 +4,19 @@ return { dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() -- ctrl+t打开文件查找 - vim.keymap.set('n', '', 'FzfLua files', {}) + vim.keymap.set('n', '', function() + -- 查找当前文件所在目录及其父目录下是否有 .git 文件夹 + local is_git = vim.fs.root(0, '.git') + if is_git then + require('fzf-lua').git_files() + else + require('fzf-lua').files() + end + end) -- ctrl+f打开字符串查找 vim.keymap.set('n', '', 'FzfLua grep', {}) require("fzf-lua").setup({ - fzf_bin = "sk", + -- fzf_bin = "sk", keymap = { fzf = { -- fzf '--bind=' options diff --git a/lua/lazy/plugins/gemini.lua b/lua/lazy/plugins/gemini.lua deleted file mode 100644 index 76193c2..0000000 --- a/lua/lazy/plugins/gemini.lua +++ /dev/null @@ -1,7 +0,0 @@ -return { - "jonroosevelt/gemini-cli.nvim", - dependencies = {}, - config = function() - require("gemini").setup() - end, -} diff --git a/lua/lazy/plugins/gitstatus.lua b/lua/lazy/plugins/gitstatus.lua index a7fc6f3..830c05e 100644 --- a/lua/lazy/plugins/gitstatus.lua +++ b/lua/lazy/plugins/gitstatus.lua @@ -6,6 +6,25 @@ return { 'lewis6991/gitsigns.nvim', build = ':TSUpdate', config = function() - require('gitsigns').setup() + require('gitsigns').setup { + 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', 't=', function() + gitsigns.nav_hunk('next') + end) + map('n', 't-', function() + gitsigns.nav_hunk('prev') + end) + -- show diff + map('n', 'hd', gitsigns.diffthis) + end + } end } diff --git a/lua/lazy/plugins/lspconfig.lua b/lua/lazy/plugins/lspconfig.lua index a3dbfc3..78c375a 100644 --- a/lua/lazy/plugins/lspconfig.lua +++ b/lua/lazy/plugins/lspconfig.lua @@ -1,21 +1,36 @@ +-- 判断 CPU 架构 +local arch = jit and jit.arch or "" +local is_arm = arch:match("arm") or arch:match("aarch64") + +-- 需要安装的 LSP +local servers = { + "lua_ls", + "rust_analyzer", + "pylsp", + -- "gopls", +} + +-- 如果不是 ARM 架构,则追加 LSP +if not is_arm then + local extra_servers = { + "marksman", + "ts_ls", + "svelte", + "cssls", + "html", + } + vim.list_extend(servers, extra_servers) +end + return { "neovim/nvim-lspconfig", dependencies = { -- 通过mason来自动安装语言服务器并启用 - { "mason-org/mason.nvim", opts = {} }, + { "mason-org/mason.nvim", opts = {} }, { "mason-org/mason-lspconfig.nvim", opts = { - ensure_installed = { - "lua_ls", - "rust_analyzer", - "marksman", - "pylsp", - "ts_ls", - "cssls", - "html", - -- "gopls", - }, + ensure_installed = servers, automatic_enable = { exclude = {}, }, @@ -25,18 +40,17 @@ return { }, config = function() -- 快捷键的映射 -vim.keymap.set("n", "h", vim.lsp.buf.hover, opts) -- h显示提示文档 -vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) -- gd跳转到定义 -vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) -- gD跳转到声明(例如c语言中的头文件中的原型、一个变量的extern声明) -vim.keymap.set("n", "go", vim.lsp.buf.type_definition, opts) -- go跳转到变量类型定义的位置(例如一些自定义类型) -vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) -- gr跳转到引用了对应变量或函数的位置 -vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- rn变量重命名 -vim.keymap.set("n", "aw", vim.lsp.buf.code_action, opts) -- aw可以在出现警告或错误的地方打开建议的修复方法 -vim.keymap.set("n", "d", vim.diagnostic.open_float, opts) -- d浮动窗口显示所在行警告或错误信息 -vim.keymap.set("n", "-", vim.diagnostic.goto_prev, opts) -- -跳转到上一处警告或错误的地方 -vim.keymap.set("n", "=", vim.diagnostic.goto_next, opts) -- +跳转到下一处警告或错误的地方 + vim.keymap.set("n", "h", vim.lsp.buf.hover, opts) -- h显示提示文档 + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) -- gd跳转到定义 + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) -- gD跳转到声明(例如c语言中的头文件中的原型、一个变量的extern声明) + vim.keymap.set("n", "go", vim.lsp.buf.type_definition, opts) -- go跳转到变量类型定义的位置(例如一些自定义类型) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) -- gr跳转到引用了对应变量或函数的位置 + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- rn变量重命名 + vim.keymap.set("n", "aw", vim.lsp.buf.code_action, opts) -- aw可以在出现警告或错误的地方打开建议的修复方法 + vim.keymap.set("n", "d", vim.diagnostic.open_float, opts) -- d浮动窗口显示所在行警告或错误信息 + vim.keymap.set("n", "-", vim.diagnostic.goto_prev, opts) -- -跳转到上一处警告或错误的地方 + vim.keymap.set("n", "=", vim.diagnostic.goto_next, opts) -- +跳转到下一处警告或错误的地方 -- vim.keymap.set({ 'n', 'x' }, 'f', function() vim.lsp.buf.format({ async = true }) end, opts) -- f进行代码格式化 - -- 诊断信息的图标 vim.diagnostic.config({ signs = { @@ -49,12 +63,33 @@ vim.keymap.set("n", "=", vim.diagnostic.goto_next, opts) -- +跳 }, }) + -- uv隔离的虚拟环使用项目根目录下 .venv 里的 Python 解析器来分析代码 + vim.lsp.config("pylsp", { + on_init = function(client) + local root_dir = client.config.root_dir + local venv_python = root_dir .. "/.venv/bin/python" + if vim.fn.filereadable(venv_python) == 1 then + client.config.settings.pylsp.plugins.jedi.environment = venv_python + client.notify("workspace/didChangeConfiguration", { settings = client.config.settings }) + end + return true + end, + settings = { + pylsp = { + plugins = { + jedi = { + environment = nil, + }, + }, + }, + }, + }) -- 特定语言开启inlay-hints等自定义配置 require("inlay-hints").setup() vim.lsp.config("lua_ls", { settings = { ["Lua"] = { - hint = { -- Lua开启hints + hint = { -- Lua开启hints enable = true, -- necessary }, diagnostics = { diff --git a/lua/lazy/plugins/markdownpreview.lua b/lua/lazy/plugins/markdownpreview.lua index 4194668..814e697 100644 --- a/lua/lazy/plugins/markdownpreview.lua +++ b/lua/lazy/plugins/markdownpreview.lua @@ -5,7 +5,8 @@ return { config = function() require("peek").setup({ port = 9000, - app = { "firefox-esr", "-private-window" }, + app = { "zen", "-private-window" }, + -- app = { "firefox-esr", "-private-window" }, -- app = { "google-chrome-stable", "--app=http://localhost:9000/?theme=dark", "--incognito" }, }) vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {}) diff --git a/lua/lazy/plugins/television.lua b/lua/lazy/plugins/television.lua new file mode 100644 index 0000000..b80d744 --- /dev/null +++ b/lua/lazy/plugins/television.lua @@ -0,0 +1,34 @@ +return { + "alexpasmantier/tv.nvim", + config = function() + vim.keymap.set('n', '', function() + if vim.fs.root(0, '.git') then + vim.cmd('Tv git-files') + else + vim.cmd('Tv files') + end + end, { desc = "Smart Tv: git-files or files" }) + local h = require('tv').handlers + require("tv").setup { + channels = { + ["git-files"] = { + handlers = { + [""] = h.open_as_files, + }, + }, + files = { + handlers = { + [""] = h.open_as_files, -- default: open selected files + }, + }, + -- `text`: ripgrep search through file contents + text = { + keybinding = '', + handlers = { + [''] = h.open_at_line, -- Jump to line:col in file + }, + }, + }, + } + end, +} diff --git a/lua/lazy/plugins/topbar.lua b/lua/lazy/plugins/topbar.lua index 904697d..8759733 100644 --- a/lua/lazy/plugins/topbar.lua +++ b/lua/lazy/plugins/topbar.lua @@ -3,16 +3,24 @@ -- === local map = require("core.keymap") --- 在标签之间移动 +-- 新建空缓冲区,貌似是neovim自带的 +map:cmd('tu', 'enew') +-- 关闭当前缓冲区,貌似是neovim自带的,完整命令bdelete +map:cmd('tq', 'bd') + +-- 在缓冲区之间移动 map:cmd('tn', 'BufferLineCyclePrev') map:cmd('ti', 'BufferLineCycleNext') --- 移动标签的位置 +-- 移动缓冲区的位置 map:cmd('tmn', 'BufferLineMovePrev') map:cmd('tmi', 'BufferLineMoveNext') --- 关闭标签,貌似是neovim自带的,完整命令bdelete -map:cmd('tq', 'bd') +-- 关闭缓冲区 +map:cmd('tN', 'BufferLineCloseLeft') +map:cmd('tI', 'BufferLineCloseRight') +map:cmd('tQ', 'BufferLineCloseOthers') + return { "akinsho/bufferline.nvim", config = function() diff --git a/lua/lazy/plugins/translate.lua b/lua/lazy/plugins/translate.lua index 4a13693..a9ce2cc 100644 --- a/lua/lazy/plugins/translate.lua +++ b/lua/lazy/plugins/translate.lua @@ -3,6 +3,8 @@ return { config = function() vim.api.nvim_set_keymap('n', 'tr', "viw:Translate ZH -output=replace", { noremap = true, silent = true }) vim.api.nvim_set_keymap('v', 'tr', ":'<,'>Translate ZH -output=replace", { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'te', "viw:Translate EN -output=replace", { noremap = true, silent = true }) + vim.api.nvim_set_keymap('v', 'te', ":'<,'>Translate EN -output=replace", { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', 'ts', "viw:Translate ZH", { noremap = true, silent = true }) vim.api.nvim_set_keymap('v', 'ts', ":'<,'>Translate ZH", { noremap = true, silent = true }) @@ -10,13 +12,13 @@ return { default = { command = "translate_shell", }, - preset = { - command = { - translate_shell = { - args = { "-e", "bing" } - } - } - } + -- preset = { + -- command = { + -- translate_shell = { + -- args = { "-e", "bing" } + -- } + -- } + -- } }) end }