From a296f56268c3b404a7c80353c4a1a4e8da627935 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Wed, 10 Jun 2026 16:59:38 +0800 Subject: [PATCH 01/29] initial: snapshot from ~/.config/nvim --- .gitignore | 1 + init.lua | 46 +++ lua/G.lua | 59 ++++ lua/keymap.lua | 46 +++ lua/lsp/basedpyright.lua | 22 ++ lua/lsp/bash.lua | 11 + lua/lsp/c.lua | 11 + lua/lsp/go.lua | 18 ++ lua/lsp/json.lua | 4 + lua/lsp/lua.lua | 32 ++ lua/lsp/markdown.lua | 2 + lua/lsp/pyright.lua | 11 + lua/lsp/yaml.lua | 12 + lua/options.lua | 91 ++++++ lua/plugs.lua | 32 ++ lua/plugs/dev.lua | 51 ++++ lua/plugs/edit-plugs.lua | 109 +++++++ lua/plugs/nvim-lspconfig.lua | 352 ++++++++++++++++++++++ lua/plugs/nvimtree.lua | 40 +++ lua/plugs/theme.lua | 82 ++++++ lua/vsc.lua | 4 + snippets/c.json | 26 ++ snippets/c/acm/Class_Data.code-snippets | 303 +++++++++++++++++++ snippets/c/acm/Class_Graph.code-snippets | 359 +++++++++++++++++++++++ snippets/c/acm/Class_Math.code-snippets | 108 +++++++ snippets/go.json | 43 +++ snippets/json.json | 13 + snippets/lua.json | 3 + 28 files changed, 1891 insertions(+) create mode 100644 .gitignore create mode 100644 init.lua create mode 100644 lua/G.lua create mode 100644 lua/keymap.lua create mode 100644 lua/lsp/basedpyright.lua create mode 100644 lua/lsp/bash.lua create mode 100644 lua/lsp/c.lua create mode 100644 lua/lsp/go.lua create mode 100644 lua/lsp/json.lua create mode 100644 lua/lsp/lua.lua create mode 100644 lua/lsp/markdown.lua create mode 100644 lua/lsp/pyright.lua create mode 100644 lua/lsp/yaml.lua create mode 100644 lua/options.lua create mode 100644 lua/plugs.lua create mode 100644 lua/plugs/dev.lua create mode 100644 lua/plugs/edit-plugs.lua create mode 100644 lua/plugs/nvim-lspconfig.lua create mode 100644 lua/plugs/nvimtree.lua create mode 100644 lua/plugs/theme.lua create mode 100644 lua/vsc.lua create mode 100644 snippets/c.json create mode 100644 snippets/c/acm/Class_Data.code-snippets create mode 100644 snippets/c/acm/Class_Graph.code-snippets create mode 100644 snippets/c/acm/Class_Math.code-snippets create mode 100644 snippets/go.json create mode 100644 snippets/json.json create mode 100644 snippets/lua.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e033bc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lazy-lock.json diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..8bb8747 --- /dev/null +++ b/init.lua @@ -0,0 +1,46 @@ +G = require('G') + +if not G.g.vscode then + + local lazypath = G.fn.stdpath("data") .. "/lazy/lazy.nvim" + + if not G.loop.fs_stat(lazypath) then + G.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) + + + G.fn.system({ + "git", + "config", + "--global", + "credential.helper", + "store", + }) + end + + G.opt.rtp:prepend(lazypath) + + require("keymap") + + + if G.g.vscode then + require('vscode') + else + require("options") + local clone_prefix = G.use_ssh and "git@github.com:%s.git" or "https://github.com/%s.git" + require("lazy").setup( + require('plugs'), { + lockfile = G.fn.stdpath("data") .. "/lazy/lazy-lock.json", + git = { + url_format = clone_prefix, + } + } + ) + end +end diff --git a/lua/G.lua b/lua/G.lua new file mode 100644 index 0000000..6fe8152 --- /dev/null +++ b/lua/G.lua @@ -0,0 +1,59 @@ +local G = {} + +G.use_ssh = false + +G.g = vim.g +G.b = vim.b +G.o = vim.o +G.fn = vim.fn +G.api = vim.api +G.opt = vim.opt +G.loop = vim.loop +G.lb = vim.lsp.buf +G.dic = vim.diagnostic +G.cgp = vim.nvim_create_augroup + +function G.map(maps) + for _, map in pairs(maps) do + if #map == 3 then + vim.keymap.set(map[1], map[2], map[3], { noremap = true }) + elseif #map == 4 then + vim.keymap.set(map[1], map[2], map[3], map[4]) + else + print("太多变量了") + end + --G.api.nvim_set_keymap(map[1], map[2], map[3], map[4]) + end +end + +function G.delmap(maps) + for _, map in pairs(maps) do + if #map == 2 then + vim.keymap.del(map[1], map[2], {}) + elseif #map == 3 then + vim.keymap.del(map[1], map[2], map[3]) + else + print("太多变量了") + end + end +end + +function G.cmd(cmd) + G.api.nvim_command(cmd) +end + +function G.exec(c) + G.api.nvim_exec(c) +end + +function G.eval(c) + return G.api.nvim_eval(c) +end + +function G.au(even, opts) + return G.api.nvim_create_autocmd(even, opts) +end + +G.g.mapleader = ' ' + +return G diff --git a/lua/keymap.lua b/lua/keymap.lua new file mode 100644 index 0000000..9b04fd1 --- /dev/null +++ b/lua/keymap.lua @@ -0,0 +1,46 @@ +local opt = { noremap = true } + +-- base +G.map({ + { 'n', 'nh', ':nohlsearch', opt }, + { 'n', 'rp', ':%s/', opt }, + + { 'v', 'L', '$', opt }, + { 'v', 'H', '^', opt }, + { 'n', 'L', '$', opt }, + { 'n', 'H', '^', opt }, + { 'v', '>', '>gv', opt }, + { 'v', '<', '', '>>', opt }, + { 'n', '<', '<<', opt }, + { 'n', '?', ':set hlsearch?', opt }, + { 'n', '/', ':set hlsearch/', opt }, + + { 'n', '', ':tabn', opt }, + { 'n', '', ':tabp', opt }, + + + { 'n', '', 'j', opt }, + { 'n', '', 'h', opt }, + { 'n', '', 'k', opt }, + { 'n', '', 'l', opt }, + + + { 'n', '', ':q', opt }, + { 'n', '', ':w !sudo tee %', opt }, + { 'n', '', ':q!', opt }, + { 'v', '', '"+y', opt }, + + + + { 'n', 'y', 'ggyG', opt }, + { 'n', 'p', 'ggpG', opt }, + { 'n', 'v', 'ggVG', opt }, + + { 'n', '', ':res -5', opt }, + { 'n', '', ':res +5', opt }, + { 'n', '', ':vertical resize -5', opt }, + { 'n', '', ':vertical resize +5', opt }, + +}) diff --git a/lua/lsp/basedpyright.lua b/lua/lsp/basedpyright.lua new file mode 100644 index 0000000..3be769f --- /dev/null +++ b/lua/lsp/basedpyright.lua @@ -0,0 +1,22 @@ +return { + -- capabilities = require("cmp_nvim_lsp").default_capabilities(), + settings = { + basedpyright = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "openFilesOnly", + useLibraryCodeForTypes = true, + typeCheckingMode = "standard" + }, + }, + }, + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term python3 %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/bash.lua b/lua/lsp/bash.lua new file mode 100644 index 0000000..74c9c6a --- /dev/null +++ b/lua/lsp/bash.lua @@ -0,0 +1,11 @@ +return{ + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term sh %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/c.lua b/lua/lsp/c.lua new file mode 100644 index 0000000..b34d457 --- /dev/null +++ b/lua/lsp/c.lua @@ -0,0 +1,11 @@ +return { + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term g++ "%" -o "%<" && ./"%<" && rm "%<"]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/go.lua b/lua/lsp/go.lua new file mode 100644 index 0000000..4b7eef4 --- /dev/null +++ b/lua/lsp/go.lua @@ -0,0 +1,18 @@ +return { + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term go run %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + G.api.nvim_create_user_command('Rgin', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term go run ./main.go]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/json.lua b/lua/lsp/json.lua new file mode 100644 index 0000000..a6cd7dd --- /dev/null +++ b/lua/lsp/json.lua @@ -0,0 +1,4 @@ +return { + on_attach = function() + end +} diff --git a/lua/lsp/lua.lua b/lua/lsp/lua.lua new file mode 100644 index 0000000..fdd0fde --- /dev/null +++ b/lua/lsp/lua.lua @@ -0,0 +1,32 @@ +local runtime_path = vim.split(package.path, ';') + +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") + +return { + + capabilities = require('cmp_nvim_lsp').default_capabilities(), + + settings = { + + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + globals = {'vim', 'G', 'yield', 'Candidate'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false + }, + }, + }, +} diff --git a/lua/lsp/markdown.lua b/lua/lsp/markdown.lua new file mode 100644 index 0000000..97aeadd --- /dev/null +++ b/lua/lsp/markdown.lua @@ -0,0 +1,2 @@ +return { +} diff --git a/lua/lsp/pyright.lua b/lua/lsp/pyright.lua new file mode 100644 index 0000000..d0898f9 --- /dev/null +++ b/lua/lsp/pyright.lua @@ -0,0 +1,11 @@ +return { + on_attach = function() + G.api.nvim_create_user_command('R', function() + G.cmd [[set splitbelow]] + G.cmd [[sp]] + G.cmd [[term python3 %]] + G.cmd [[resize 10]] + G.cmd [[startinsert]] + end, {}) + end +} diff --git a/lua/lsp/yaml.lua b/lua/lsp/yaml.lua new file mode 100644 index 0000000..7990cc8 --- /dev/null +++ b/lua/lsp/yaml.lua @@ -0,0 +1,12 @@ +return { + capabilities = require('cmp_nvim_lsp').default_capabilities(), + settings = { + yaml = { + schemas = { + ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*", + ["../path/relative/to/file.yml"] = "/.github/workflows/*", + ["/path/from/root/of/project"] = "/.github/workflows/*", + }, + }, + } +} diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..1a7ef51 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,91 @@ +-- +G.opt.ttimeout = true +G.opt.ttimeoutlen = 100 + +-- 行号 +G.opt.nu = true +G.opt.rnu = true +G.opt.scrolloff = 999 + +-- 自动保存 +G.opt.autowrite = true +G.opt.autowriteall = true + +-- tab键 +G.opt.sw = 2 +G.opt.ts = 2 +G.opt.softtabstop = 2 +G.opt.smarttab = true +G.opt.expandtab = true +G.opt.autoindent = true + +-- 光标 +G.opt.cursorline = true + +-- 分屏 +G.opt.splitright = true +G.opt.splitbelow = true + +-- 搜索 +G.opt.ignorecase = true +G.opt.incsearch = true + +-- 不换行 +G.opt.textwidth = 999 +G.opt.wrap = false + + +-- 文件判断 +G.cmd("filetype plugin indent on") + +-- 取消换行注释 +G.au({ "BufEnter" }, { + pattern = { "*" }, + callback = function() + -- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" } + G.opt.formatoptions = G.opt.formatoptions + - "o" -- O and o, don't continue comments + + "r" -- But do continue when pressing enter. + end, +}) + +G.au({ "InsertEnter" }, { + pattern = { "*" }, + callback = function() + G.opt.hlsearch = false + end, +}) + +G.au({ "VimEnter", "BufEnter" }, { + pattern = { "*.code-snippets" }, + callback = function() + G.cmd("setfiletype json") + end, +}) + +-- G.au({ +-- {"CmdlineEnter"}, +-- { +-- if index +-- } +-- }) + + +local function isempty(s) + return s == nil or s == "" +end + +local function use_if_defined(val, fallback) + return val ~= nil and val or fallback +end + + +local conda_prefix = os.getenv("CONDA_PREFIX") +if not isempty(conda_prefix) then + vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, conda_prefix .. "/bin/python") + vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, conda_prefix .. "/bin/python") +else + vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, "python") + vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, "python3") +end + diff --git a/lua/plugs.lua b/lua/plugs.lua new file mode 100644 index 0000000..586ff2b --- /dev/null +++ b/lua/plugs.lua @@ -0,0 +1,32 @@ +return { + + require('plugs.nvim-lspconfig'), + require('plugs.nvimtree'), -- nvimtree + require('plugs.theme'), -- theme + require("plugs.edit-plugs"), + require("plugs.dev"), + + + -- leetcode刷题 + -- { + -- "kawre/leetcode.nvim", + -- build = ":TSUpdate html", + -- dependencies = { + -- "nvim-telescope/telescope.nvim", + -- "nvim-lua/plenary.nvim", -- telescope 所需 + -- "MunifTanjim/nui.nvim", + + -- -- 可选 + -- "nvim-treesitter/nvim-treesitter", + -- "rcarriga/nvim-notify", + -- "nvim-tree/nvim-web-devicons", + -- }, + -- opts = { + -- -- 配置放在这里 + -- cn = { + -- enabled = true, + -- }, + -- }, + -- }, + +} diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua new file mode 100644 index 0000000..e332706 --- /dev/null +++ b/lua/plugs/dev.lua @@ -0,0 +1,51 @@ +return { + 'lilydjwg/colorizer', -- 颜色识别 + -- "rest-nvim/rest.nvim", + -- dependencies = { { "nvim-lua/plenary.nvim" } }, + -- config = function() + -- require("rest-nvim").setup({ + -- --- Get the same options from Packer setup + -- }) + -- end + -- }, + -- { + -- -- go开发 + -- "ray-x/go.nvim", + -- dependencies = { -- optional packages + -- "ray-x/guihua.lua", + -- "neovim/nvim-lspconfig", + -- "nvim-treesitter/nvim-treesitter", + -- }, + -- config = function() + -- require("go").setup() + -- end, + -- -- event = { "CmdlineEnter" }, + -- ft = { "go", 'gomod' }, + -- build = ':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries + -- }, + { + -- conda 环境 + "kmontocam/nvim-conda", + dependencies = { "nvim-lua/plenary.nvim" }, + }, + { + -- 终端 + 'akinsho/toggleterm.nvim', + version = "*", + config = function() + require("toggleterm").setup { + -- size can be a number or function which is passed the current terminal + size = 10, + open_mapping = [[]], + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_filetypes = {}, + shade_terminals = true, + shading_factor = 1, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + start_in_insert = true, + insert_mappings = true, -- whether or not the open mapping applies in insert mode + persist_size = true, + direction = 'horizontal', + } + end + } +} diff --git a/lua/plugs/edit-plugs.lua b/lua/plugs/edit-plugs.lua new file mode 100644 index 0000000..d7fe61b --- /dev/null +++ b/lua/plugs/edit-plugs.lua @@ -0,0 +1,109 @@ +return { + 'vijaymarupudi/nvim-fzf', -- fzf + { + -- surround 和 wildfire 配合有神奇的效果 + 'tpope/vim-surround', + 'gcmt/wildfire.vim', + + -- 括号箭头 + 'yaocccc/nvim-hlchunk', + + }, + -- 多光标 + { + 'terryma/vim-multiple-cursors', + }, + { + --格式整理 + { + 'junegunn/vim-easy-align', + config = function() + G.map({ + { "v", "ga", ":EasyAlign", { noremap = true } }, + { "v", "=", ":EasyAlign", { noremap = true } }, + }) + end + }, + }, + { + -- 注释插件 + { + 'tpope/vim-commentary', + } + }, + { + 'github/copilot.vim', -- github copilot + }, + { + 'windwp/nvim-autopairs', + event = "InsertEnter", + opts = {}, -- this is equalent to setup({}) function + config = function() + require('nvim-autopairs').setup({ + disable_filetype = { "vim" }, + }) + end + }, + -- { + -- 'kevinhwang91/nvim-ufo', + -- dependencies = { + -- 'kevinhwang91/promise-async' + -- }, + -- config = function () + -- require("ufo").setup() + -- end + + -- }, + { + -- hop + "phaazon/hop.nvim", + branch = "v2", + keys = { + "f", "F", "t", "T", + "" + }, + lazy = true, + config = function() + require("hop").setup { keys = 'asdfghjkl;' } + local hop = require('hop') + local directions = require('hop.hint').HintDirection + G.map({ + { "n", "", ":HopChar2MW", { noremap = true } }, + { "n", "f", + function() + hop.hint_char1({ + direction = directions.AFTER_CURSOR, + current_line_only = true + }) + end, { noremap = true } + }, + { "n", "F", + function() + hop.hint_char1({ + direction = directions.BEFORE_CURSOR, + current_line_only = true + }) + end, { noremap = true } + }, + { "n", "t", + function() + hop.hint_char1({ + direction = directions.AFTER_CURSOR, + current_line_only = true, + hint_offset = -1 + }) + end, { noremap = true } + }, + { "n", "T", + function() + hop.hint_char1({ + direction = directions.BEFORE_CURSOR, + current_line_only = true, + hint_offset = -1 + }) + end, { noremap = true } + }, + }) + end + } +} diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua new file mode 100644 index 0000000..9edd0b6 --- /dev/null +++ b/lua/plugs/nvim-lspconfig.lua @@ -0,0 +1,352 @@ +return { + { + -- lsp的config + "neovim/nvim-lspconfig", + dependencies = { + "folke/neodev.nvim", + }, + config = function() + require 'neodev'.setup {} + + -- 定义需要启用的服务器列表及其对应的配置 + local servers = { + lua_ls = require('lsp.lua'), + clangd = require('lsp.c'), + bashls = require('lsp.bash'), + basedpyright = require('lsp.basedpyright'), + yamlls = require('lsp.yaml'), + gopls = require('lsp.go'), + jsonls = require('lsp.json'), + } + + -- 使用 Neovim 0.11+ 的新 API 进行配置和启用 + for server, config in pairs(servers) do + vim.lsp.config(server, config) + vim.lsp.enable(server) + end + -- require 'lspconfig'.lua_ls.setup(require('lsp.lua')) + -- require 'lspconfig'.clangd.setup(require('lsp.c')) + -- require 'lspconfig'.bashls.setup(require('lsp.bash')) + -- require 'lspconfig'.basedpyright.setup(require('lsp.basedpyright')) + -- require 'lspconfig'.yamlls.setup(require('lsp.yaml')) + -- require 'lspconfig'.gopls.setup(require('lsp.go')) + -- require 'lspconfig'.jsonls.setup(require('lsp.json')) + + + G.map({ + + { 'n', 'rn', 'lua vim.lsp.buf.rename()' }, + + { 'n', 'gd', 'lua vim.lsp.buf.definition()' }, + { 'n', 'gh', 'lua vim.lsp.buf.hover()' }, + { 'n', 'gD', 'lua vim.lsp.buf.declaration()' }, + { 'n', 'gi', 'lua vim.lsp.buf.implementation()' }, + { 'n', 'gr', 'lua vim.lsp.buf.references()' }, + { 'n', '', 'lua vim.lsp.buf.format()' }, + + }) + end + + }, + { + -- lsp + "williamboman/mason-lspconfig.nvim", + dependencies = { + "williamboman/mason.nvim", -- lsp 下载器 + }, + config = function() + require "mason".setup { + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } + } + require("mason-lspconfig").setup({ + ensure_installed = { + "bashls", + -- "basedpyright", + "lua_ls", + "jsonls", + "yamlls", + } + }) + end + }, + { -- + 'simrat39/symbols-outline.nvim', + config = function() + local opts = { + highlight_hovered_item = true, + show_guides = true, + auto_preview = false, + position = 'right', + relative_width = true, + width = 25, + auto_close = false, + show_numbers = false, + show_relative_numbers = false, + show_symbol_details = true, + preview_bg_highlight = 'Pmenu', + autofold_depth = nil, + auto_unfold_hover = true, + fold_markers = { '', '' }, + wrap = false, + keymaps = { -- These keymaps can be a string or a table for multiple keys + close = { "", "q" }, + goto_location = "", + focus_location = "h", + hover_symbol = "", + toggle_preview = "K", + rename_symbol = "r", + code_actions = "a", + fold = "o", + unfold = "l", + fold_all = "W", + unfold_all = "E", + fold_reset = "R", + }, + lsp_blacklist = {}, + symbol_blacklist = {}, + symbols = { + File = { icon = "", hl = "@text.uri" }, + Module = { icon = "", hl = "@namespace" }, + Namespace = { icon = "", hl = "@namespace" }, + Package = { icon = "", hl = "@namespace" }, + Class = { icon = "𝓒", hl = "@type" }, + Method = { icon = "ƒ", hl = "@method" }, + Property = { icon = "", hl = "@method" }, + Field = { icon = "", hl = "@field" }, + Constructor = { icon = "", hl = "@constructor" }, + Enum = { icon = "ℰ", hl = "@type" }, + Interface = { icon = "ﰮ", hl = "@type" }, + Function = { icon = "", hl = "@function" }, + Variable = { icon = "", hl = "@constant" }, + Constant = { icon = "", hl = "@constant" }, + String = { icon = "𝓐", hl = "@string" }, + Number = { icon = "#", hl = "@number" }, + Boolean = { icon = "⊨", hl = "@boolean" }, + Array = { icon = "", hl = "@constant" }, + Object = { icon = "⦿", hl = "@type" }, + Key = { icon = "🔐", hl = "@type" }, + Null = { icon = "NULL", hl = "@type" }, + EnumMember = { icon = "", hl = "@field" }, + Struct = { icon = "𝓢", hl = "@type" }, + Event = { icon = "🗲", hl = "@type" }, + Operator = { icon = "+", hl = "@operator" }, + TypeParameter = { icon = "𝙏", hl = "@parameter" }, + Component = { icon = "", hl = "@function" }, + Fragment = { icon = "", hl = "@constant" }, + }, + } + require("symbols-outline").setup(opts) + G.map({ + { "n", "", "SymbolsOutline", { noremap = true } }, + }) + end + }, + { + -- lsp补全 + { + "hrsh7th/nvim-cmp", + dependencies = { + 'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' } + 'hrsh7th/cmp-buffer', -- { name = 'buffer' }, + 'hrsh7th/cmp-path', -- { name = 'path' } + 'hrsh7th/cmp-cmdline', -- { name = 'cmdline' } + { + 'hrsh7th/vim-vsnip', + config = function() + G.g.vsnip_snippet_dir = G.fn.stdpath("config") .. "/snippets" + end + }, + 'hrsh7th/cmp-vsnip', + 'onsails/lspkind-nvim', + }, + config = function() + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(G.api.nvim_win_get_cursor(0)) + return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil + end + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + local cmp = require('cmp') + local cmp_opt = { + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + end, + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + }, + { name = 'buffer' }, + { name = 'path' } + ), + mapping = cmp.mapping.preset.insert({ + + [""] = cmp.mapping({ + i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + c = function(fallback) + if cmp.visible() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) + else + fallback() + end + end, + }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + + }), + + window = { + completion = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + col_offset = -3, + side_padding = 0, + border = "rounded", + scrollbar = false, + }, + documentation = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + border = "rounded", + scrollbar = false, + }, + }, + + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50, })(entry, vim_item) + local strings = vim.split(kind.kind, "%s", { trimempty = true }) + kind.kind = " " .. (strings[1] or "") .. " " + kind.menu = " (" .. (strings[2] or "") .. ")" + return kind + end, + }, + } + require('cmp').setup(cmp_opt) + end, + }, + + { + -- 语法高亮 -- + 'nvim-treesitter/nvim-treesitter', + config = function() + local treesitter_opt = { + ensure_installed = { + -- "c", + -- "cpp", + -- "python", + -- "java", + -- "lua", + -- "bash", + -- "vimdoc", + }, + indent = { enable = true }, + ignore_install = { + "txt", + "go" + }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + disable = function(_, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + additional_vim_regex_highlighting = false, + }, + parsers = { + html = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = { "src/parser.c" }, + branch = "main" + } + } + } + } + require 'nvim-treesitter'.setup(treesitter_opt) + require 'nvim-treesitter.install'.prefer_git = true + if G.use_ssh then + local parsers = require 'nvim-treesitter.parsers'.get_parser_configs() + for _, p in pairs(parsers) do + p.install_info.url = p.install_info.url:gsub("https://github/com/", "git@github.com:") + end + end + end + }, + }, + { + 'fgheng/winbar.nvim', + config = function() + require('winbar').setup({ + enabled = true, -- 是否启动winbar + + -- show_file_path = true, -- 是否显示文件路径 + show_symbols = true, -- 是否显示函数标签 + + -- 颜色配置,为空,将使用默认配色 + colors = { + path = '#aaffff', -- 路径的颜色,比如#ababab + file_name = '#bbbbff', -- 文件名称的颜色,比如#acacac + symbols = '#aaffaa', -- 函数颜色 + }, + + -- 图标配置 + icons = { + seperator = '>', -- 路径分割符号 + editor_state = '●', + lock_icon = '', + }, + + -- 关闭winbar的窗口 + exclude_filetype = { + 'help', + 'startify', + 'dashboard', + 'packer', + 'neogitstatus', + 'NvimTree', + 'Trouble', + 'alpha', + 'lir', + 'Outline', + 'spectre_panel', + 'toggleterm', + 'qf', + } + }) + end + }, +} diff --git a/lua/plugs/nvimtree.lua b/lua/plugs/nvimtree.lua new file mode 100644 index 0000000..c2f2607 --- /dev/null +++ b/lua/plugs/nvimtree.lua @@ -0,0 +1,40 @@ +return { + "nvim-tree/nvim-tree.lua", + dependencies = { + 'kyazdani42/nvim-web-devicons' + }, + keys = { + "" + }, + config = function() + require 'nvim-web-devicons'.setup {} + + require 'nvim-tree'.setup { + sort_by = "case_sensitive", + view = { + width = 30, + }, + filters = { dotfiles = true, }, + git = { enable = true }, + on_attach = function(bufnr) + local api = require 'nvim-tree.api' + api.config.mappings.default_on_attach(bufnr) + + -- override a default + G.map({ + { 'n', 'v', api.node.open.vertical, { buffer = bufnr } }, + { 'n', 's', api.node.open.horizontal, { buffer = bufnr } }, + }) + + G.delmap({ + { 'n', '', { buffer = bufnr } }, + { 'n', '', { buffer = bufnr } }, + { 'n', '', { buffer = bufnr } }, + }) + end + } + G.map({ + { "n", "", ":NvimTreeToggle", { noremap = true } }, + }) + end +} diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua new file mode 100644 index 0000000..013bed5 --- /dev/null +++ b/lua/plugs/theme.lua @@ -0,0 +1,82 @@ +return { + { + 'folke/tokyonight.nvim', + config = function() + G.cmd("colorscheme tokyonight") -- 主题 + G.opt.background = 'dark' -- 背景 + end + }, + { + -- line插件 + 'kdheepak/tabline.nvim', + 'nvim-lualine/lualine.nvim', + config = function() + require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = { { + 'filename', + file_status = false, + path = 1 + } }, + lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_y = { 'progress' }, + lualine_z = {} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} + } + require('tabline').setup { + -- Defaults configuration options + enable = true, + options = { + -- If lualine is installed tabline will use separators configured in lualine by default. + -- These options can be used to override those settings. + section_separators = { ' ', ' ' }, + component_separators = { '', '' }, + max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 + show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named + show_devicons = true, -- this shows devicons in buffer section + show_bufnr = false, -- this appends [bufnr] to buffer section, + show_filename_only = true, -- shows base filename only instead of relative path in filename + modified_icon = "+ ", -- change the default modified icon + modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified + show_tabs_only = false, -- this shows only tabs instead of tabs + buffers + }, + G.cmd [[ + set guioptions-=e " Use showtabline in gui vim + set sessionoptions+=tabpages,globals " store tabpages and globals in session + ]] + } + end, + }, +} diff --git a/lua/vsc.lua b/lua/vsc.lua new file mode 100644 index 0000000..0abf89d --- /dev/null +++ b/lua/vsc.lua @@ -0,0 +1,4 @@ +require 'lazy'.setup({ + require('plugs.edit-plugs'), + -- 'vijaymarupudi/nvim-fzf', -- fzf +}) diff --git a/snippets/c.json b/snippets/c.json new file mode 100644 index 0000000..94d29ce --- /dev/null +++ b/snippets/c.json @@ -0,0 +1,26 @@ +{ + "for": { + "prefix": "for", + "body": [ + " for(int $1 = $2; $1 < $3; $1+=$4) {", + " $5", + " }" + ] + }, + "for1": { + "prefix": "for1", + "body": [ + " for(int $1 = $2; $1 < $3; $1++) {", + " $4", + " }" + ] + }, + "fori": { + "prefix": "fori", + "body": [ + " for(int i = $1; i < $2; i++) {", + " $3", + " }" + ] + } +} diff --git a/snippets/c/acm/Class_Data.code-snippets b/snippets/c/acm/Class_Data.code-snippets new file mode 100644 index 0000000..bc82d63 --- /dev/null +++ b/snippets/c/acm/Class_Data.code-snippets @@ -0,0 +1,303 @@ +{ + "Class_Array_tree": { + "prefix": "Class_Array_tree", + "body": [ + "", + "template ", + "class Array_tree {", + " public:", + " Array_tree() {}", + " Array_tree(int n) { this->n = n, tree = vector(n + 1); }", + " void add(int id, T key) {", + " for (int i = id; i <= n; i += lowbit(i)) tree[i] += key;", + " }", + "", + " T get_sum(int id) {", + " T sum = 0;", + " for (int i = id; i; i -= lowbit(i)) sum += tree[i];", + " return sum;", + " }", + "", + " T get_sum(int l, int r) { return get_sum(r) - get_sum(l - 1); }", + "", + " private:", + " int n;", + " vector tree;", + " int lowbit(int x) { return x & -x; }", + "};", + "" + ] + }, + "Class_SGM_Tree": { + "prefix": "Class_SGM_Tree", + "body": [ + "", + "class SGM_Tree {", + " public:", + " class point {", + " public:", + " ll sum, maxi, mini;", + " };", + "", + " vll a, lazy;", + " int n;", + " ll sum, maxi, mini;", + " vector tree;", + "", + " SGM_Tree() {}", + " SGM_Tree(int n, vi v) {", + " // a下标默认从1开始,只需开n个点,不需要n + 1", + " this->n = n;", + " lazy = vll(n * 4 + 1);", + " a.push_back(0);", + " for (int i = 1; i <= n; i++) a.push_back(v[i]);", + " tree = vector(4 * n + 1), build(1, n, 1);", + " }", + " SGM_Tree(int n, vll v) {", + " // a下标默认从1开始,只需开n个点,不需要n + 1", + " this->n = n;", + " lazy = vll(n * 4 + 1);", + " a.push_back(0);", + " for (int i = 1; i <= n; i++) a.push_back(v[i]);", + " tree = vector(4 * n + 1), build(1, n, 1);", + " }", + " SGM_Tree(int n, int* v) {", + " // a下标默认从1开始,只需开n个点,不需要n + 1", + " this->n = n;", + " lazy = vll(n * 4 + 1);", + " a.push_back(0);", + " for (int i = 1; i <= n; i++) a.push_back(v[i]);", + " tree = vector(4 * n + 1), build(1, n, 1);", + " }", + "", + " void push_up(int k) {", + " int l = k * 2, r = k * 2 + 1;", + " tree[k].sum = tree[l].sum + tree[r].sum;", + " tree[k].maxi = max(tree[l].maxi, tree[r].maxi);", + " tree[k].mini = min(tree[l].mini, tree[r].mini);", + " }", + "", + " void push_down(int l, int r, int k) {", + " if (lazy[k]) {", + " int mid = l + r >> 1;", + " lazy[k * 2] += lazy[k];", + " lazy[k * 2 + 1] += lazy[k];", + " tree[k * 2].sum += lazy[k] * (mid - l + 1);", + " tree[k * 2 + 1].sum += lazy[k] * (r - mid);", + " tree[k * 2].maxi += lazy[k];", + " tree[k * 2 + 1].maxi += lazy[k];", + " tree[k * 2].mini += lazy[k];", + " tree[k * 2 + 1].mini += lazy[k];", + " lazy[k] = 0;", + " }", + " }", + "", + " void get_updata(int l, int r, int k, ll value) {", + " tree[k].sum += value * (r - l + 1);", + " tree[k].maxi += value;", + " tree[k].mini += value;", + " lazy[k] += value;", + " }", + "", + " void get(int k) {", + " sum += tree[k].sum;", + " maxi = max(maxi, tree[k].maxi);", + " mini = min(mini, tree[k].mini);", + " }", + "", + " void build(int l, int r, int k) {", + " if (l == r) {", + " tree[k].maxi = tree[k].mini = tree[k].sum = a[l];", + " return;", + " }", + " int mid = l + r >> 1;", + " build(l, mid, k * 2);", + " build(mid + 1, r, k * 2 + 1);", + " push_up(k);", + " }", + "", + " void updata(int l, int r, int L, int R, int k, ll value) {", + " if (L <= l && r <= R) {", + " get_updata(l, r, k, value);", + " return;", + " }", + " push_down(l, r, k);", + " int mid = l + r >> 1;", + " if (L <= mid) updata(l, mid, L, R, k * 2, value);", + " if (R > mid) updata(mid + 1, r, L, R, k * 2 + 1, value);", + " push_up(k);", + " }", + "", + " void query(int l, int r, int L, int R, int k) {", + " if (L <= l && r <= R) {", + " get(k);", + " return;", + " }", + " push_down(l, r, k);", + " int mid = l + r >> 1;", + " if (mid >= L) query(l, mid, L, R, 2 * k);", + " if (mid < R) query(mid + 1, r, L, R, 2 * k + 1);", + " }", + "", + " ll get_sum(int L, int R) {", + " sum = 0;", + " query(1, n, L, R, 1);", + " return sum;", + " }", + "", + " ll get_max(int L, int R) {", + " maxi = -inf;", + " query(1, n, L, R, 1);", + " return maxi;", + " }", + "", + " ll get_min(int L, int R) {", + " mini = inf;", + " query(1, n, L, R, 1);", + " return mini;", + " }", + "};", + "" + ] + }, + "Class_Dsu": { + "prefix": "Class_Dsu", + "body": [ + "", + "class Dsu {", + " public:", + "", + " vll fa, num;", + "", + " Dsu(int n) { fa = vll(n + 1), num = vll(n + 1); }", + " int find(int x) {", + " if (!fa[x]) return x;", + " return fa[x] = find(fa[x]);", + " }", + "", + " bool Dunion(int p, int q) {", + " int v = find(p), u = find(q);", + " if (v == u) return 0;", + " fa[u] = v;", + " num[v] += num[u];", + " num[u] = num[v];", + " return 1;", + " }", + " ", + "};", + "", + "ll num(int x) { return num[find(x)]; }", + "" + ] + }, + "class_Stmap": { + "prefix": "Class_StMap", + "body": [ + "", + "class st_map {", + " public:", + " st_map() {}", + " st_map(vll v) {", + " this->n = v.size(), this->a = v;", + " this->st = vector>(n + 1);", + " st_init();", + " }", + " int query(int l, int r) {", + " int len = r - l + 1;", + " int k = log(len) / log(2);", + " return max(st[l][k], st[r - (1 << k) + 1][k]);", + " }", + "", + " private:", + " int n;", + " vll a;", + " vector> st;", + " void st_init() {", + " for (int j = 0; j <= 17; j++) {", + " for (int i = 1; i + (1 << j) - 1 <= n; i++) {", + " if (j == 0)", + " st[i][j] = a[i];", + " else", + " st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);", + " }", + " }", + " }", + "};", + "" + ] + }, + "Class_HJT_tree": { + "prefix": "Class_HJT_tree", + "body": [ + "", + "template ", + "class HJT_tree {", + " //处理数据默认下标从1开始", + " public:", + " //构造函数", + " HJT_tree() {}", + " HJT_tree(vector v) {", + " base = v, this->n = base.size() - 1;", + " tree = vector(n * 32), root.push_back(build(1, n));", + " }", + "", + " void updata(int v, int x, T value) {", + " //插入函数(版本,修改位置,修改值)", + " root.push_back(insert(root[v], 1, n, x, value));", + " }", + "", + " T query(int v, int x) {", + " //查询函数(版本,查询位置)", + " return get_se(root[v], 1, n, x, x);", + " }", + "", + " T query(int v, int l, int r) {", + " //查询函数(版本,查询区间)", + " return get_se(root[v], 1, n, l, r);", + " }", + "", + " private:", + " vi root;", + " vector base;", + " int n, idx = 0;", + " struct node {", + " int l, r;", + " T data;", + " };", + " vector tree;", + " void pushup(int q) { tree[q].data = op(tree[q].l, tree[q].r); }", + " T op(int l, int r) { return max(tree[l].data, tree[r].data); }", + " T e() { return -inf; }", + " int build(int l, int r) {", + " int now = ++idx, mid = l + r >> 1;", + " if (l != r)", + " tree[now].l = build(l, mid), tree[now].r = build(mid + 1, r), pushup(now);", + " return now;", + " }", + " int insert(int old, int l, int r, int x, int value) {", + " int now = ++idx, mid = l + r >> 1;", + " tree[now] = tree[old];", + " if (l == r)", + " tree[now].data = value;", + " else {", + " if (x <= mid)", + " tree[now].l = insert(tree[old].l, l, mid, x, value);", + " else", + " tree[now].r = insert(tree[old].r, mid + 1, r, x, value);", + " pushup(now);", + " }", + " return now;", + " }", + " T get_se(int v, int l, int r, int L, int R) {", + " if (L <= l && r <= R) return tree[v].data;", + " ll mid = l + r >> 1;", + " T res = e();", + " if (L <= mid) res = max(res, get_se(tree[v].l, l, mid, L, R));", + " if (R > mid) res = max(res, get_se(tree[v].r, mid + 1, r, L, R));", + " return res;", + " }", + "};", + "" + ] + } +} diff --git a/snippets/c/acm/Class_Graph.code-snippets b/snippets/c/acm/Class_Graph.code-snippets new file mode 100644 index 0000000..cfa9bb2 --- /dev/null +++ b/snippets/c/acm/Class_Graph.code-snippets @@ -0,0 +1,359 @@ +{ + "Graph": { + "prefix": "Class_Graph", + "body": [ + "", + "template ", + "class Graph {", + " public:", + " struct edge {", + " int next, to;", + " T w;", + " };", + " int n;", + " vector> maps;", + " vector dis;", + " vector e;", + " vi head, bj;", + " Graph() {}", + "", + " Graph(int n) {", + " this->n = n, this->m = n * (n - 1);", + " head = vi(n + 1, -1), e = vector(m * 2 + 1);", + " }", + "", + " Graph(int n, int m) {", + " this->n = n, this->m = m, head = vi(n + 1, -1), e = vector(m * 2 + 1);", + " }", + "", + " void add(int u, int v, T w) {", + " e[cnt].to = v, e[cnt].next = head[u], e[cnt].w = w, head[u] = cnt++;", + " }", + "", + " void add(int u, int v) {", + " e[cnt].to = v, e[cnt].next = head[u], head[u] = cnt++;", + " }", + "", + " private:", + " int m, cnt = 0;", + "};", + "#define e g.e", + "#define head g.head", + "#define maps g.maps", + "#define add g.add", + "" + ] + }, + "Class_Graph_Dijkstra": { + "prefix": "Class_Graph_Dijkstra", + "body": [ + "", + "#define dis g.dis", + "#define bj g.bj", + "ll dijkstra(Graph g, int st, int en) {", + " dis = vll(g.n + 1, inf),", + " bj = vi(g.n + 1);", + " priority_queue, greater> q;", + " dis[st] = 0;", + " q.push({0, st});", + " while (!q.empty()) {", + " int u = q.top().y;", + " q.pop();", + " if (bj[u]) continue;", + " bj[u] = 1;", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to;", + " if (dis[v] > dis[u] + e[i].w) {", + " dis[v] = dis[u] + e[i].w;", + " q.push({dis[v], v});", + " }", + " }", + " }", + " if (dis[en] != inf)", + " return dis[en];", + " else", + " return -1;", + "}", + "" + ] + }, + "Class_Graph_SPFA": { + "prefix": "Class_Graph_SPFA", + "body": [ + "", + "ll spfa(Graph g, int st, int en) {", + " vll bj(g.n + 1), dis(g.n + 1, inf), num(g.n + 1);", + " queue q;", + " dis[st] = 0;", + " bj[st] = 1;", + " q.push(st);", + " while (q.size()) {", + " int u = q.front();", + " if (!bj[u]) continue;", + " if (num[u] > g.n + 1) return inf;//判断是否产生负环", + " bj[u] = 0, num[u]++;", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int w = e[i].w, v = e[i].to;", + " if (dis[v] > dis[u] + w) {", + " dis[v] = dis[u] + w;", + " if (!bj[v]) q.push(v);", + " }", + " }", + " }", + " if(dis[en] == inf) return -1;", + " return dis[en];", + "}", + "" + ] + }, + "Class_Graph_Kurskal": { + "prefix": "Class_Graph_Kurskal", + "body": [ + "", + "ll kruskal(Graph g, Dsu d) {", + " ll res = 0, cnt = 0;", + " sort(e.begin(), e.end());", + " for (auto i : e) {", + " int u = i.u, v = i.v, w = i.w;", + " int q = d.find(i.u), p = d.find(i.v);", + " if (d.Dunion(q, p)) cnt++, res += w;", + " if (cnt == n - 1) break;", + " }", + " return res;", + "}", + "" + ] + }, + "Class_Graph_Prim": { + "prefix": "Class_Graph_Prim", + "body": [] + }, + "Class_Graph_TreeDiam": { + "prefix": "Class_Graph_TreeDiam", + "description": "树的直径", + "body": [ + "ll TreeDiam(Graph g) {", + " vll dis1(n + 1), dis2(n + 1), p(n + 1), up(n + 1);", + " function dfs = [&](ll u, ll fa) {", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to, w = 1;", + " if (v == fa) continue;", + " ll x = dfs(v, u) + 1;", + " if (x >= dis1[u])", + " dis2[u] = dis1[u], dis1[u] = x, p[u] = v;", + " else if (x >= dis2[u])", + " dis2[u] = x;", + " }", + " return dis1[u];", + " };", + " function dfs0 = [&](ll u, ll fa) {", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to, w = 1;", + " if (v == fa) continue;", + " if (p[u] == v)", + " up[v] = max(dis2[u], up[u]) + w;", + " else", + " up[v] = max(dis1[u], up[u]) + w;", + " dfs0(v, u);", + " }", + " };", + " dfs(1, -1), dfs0(1, -1);", + " ll ans = -1;", + " for (int i = 1; i <= n + m; i++) {", + " if (dis1[i] == dis2[i] && dis1[i] == 0)", + " ans = max(ans, up[i]);", + " else", + " ans = max(ans, max(up[i], dis1[i]));", + " }", + " return ans;", + "}" + ] + }, + "Class_Graph_SCC": { + "prefix": "Class_Graph_SCC", + "body": [ + "", + "class SCC {", + " public:", + " stack stk;", + " int timestamp = 0, scc_cnt = 0, n, m;", + " vll dfn, low, in_stk, Size, id;", + " Graph g;", + "", + " SCC() {}", + "", + " SCC(Graph g) {", + " this->n = g.n, this->m = g.m, this->g = g;", + " dfn = vll(n + 1, 0);", + " low = vll(n + 1, 0);", + " in_stk = vll(n + 1, 0);", + " Size = vll(n + 1, 0);", + " id = vll(n + 1, 0);", + " for (int i = 1; i <= n; i++)", + " if (!dfn[i]) tarjan(i);", + " }", + "", + " void tarjan(int u) {", + " dfn[u] = low[u] = ++timestamp;", + " stk.push(u), in_stk[u] = 1;", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to;", + " if (!dfn[v]) {", + " tarjan(v);", + " low[u] = min(low[u], low[v]);", + " } else if (in_stk[v])", + " low[u] = min(low[u], dfn[v]);", + " }", + " if (low[u] == dfn[u]) {", + " ++scc_cnt;", + " int v;", + " do {", + " v = stk.top();", + " stk.pop();", + " in_stk[v] = 0;", + " id[v] = scc_cnt;", + " Size[scc_cnt]++;", + " } while (v != u);", + " }", + " return;", + " }", + "};", + "" + ] + }, + "Class_Graph_Euler": { + "prefix": "Class_Graph_Euler", + "body": [ + "", + "vll din, dout;", + "", + "class Euler {", + " public:", + " int n, m;", + " Graph g;", + " vector used;", + " vll path;", + " Euler() {}", + " Euler(Graph g) {", + " this->n = g.n, this->m = g.m, this->g = g;", + " used = vector(n + 1);", + " }", + "", + " void dfs_u(int u) {", + " //无向图", + " for (long long &i = head[u]; i; i = e[i].next) {", + " long long j = i & 1 ? i + 1 : i - 1;", + " if(used[i]) {", + " i = e[i].next;", + " continue;", + " }", + " used[j] = used[i] = true;", + " int t = i / 2 + 1;", + " dfs_u(e[i].to);", + " path.push_back(t);", + " }", + " }", + "", + " void dfs_o(int u) {", + " // 有向图", + " for (long long &i = head[u]; i; i = e[i].next) {", + " if(used[i]) {", + " i = e[i].next;", + " continue;", + " }", + " used[i] = true;", + " int t = i + 1;", + " dfs_o(e[i].to);", + " path.push_back(t);", + " }", + " }", + "", + "};", + "#define path eu.path", + "" + ] + }, + "Class_Graph_LCA": { + "prefix": "Class_Graph_LCA", + "body": [ + "", + "class LCA {", + " public:", + " int n;", + " vll depth, fa[33];", + "", + " LCA() {}", + " LCA(Graph g, int root) {", + " n = g.n, depth = vll(n + 1, inf);", + " for (int i = 0; i <= 32; i++) fa[i] = vll(n + 1);", + " bfs(g, root);", + " }", + "", + " void bfs(Graph g, int root) {", + " depth[0] = 0, depth[root] = 1;", + " queue q;", + " q.push(root);", + " while (q.size()) {", + " auto u = q.front();", + " q.pop();", + " for (int i = head[u]; ~i; i = e[i].next) {", + " int v = e[i].to;", + " if (depth[v] > depth[u] + 1) {", + " depth[v] = depth[u] + 1;", + " q.push(v);", + " fa[0][v] = u;", + " for (int k = 1; k <= 32; k++) fa[k][v] = fa[k - 1][fa[k - 1][v]];", + " }", + " }", + " }", + " }", + "", + " int query(int a, int b) {", + " if (depth[a] < depth[b]) swap(a, b);", + " for (int i = 32; i >= 0; i--)", + " if (depth[fa[i][a]] >= depth[b]) a = fa[i][a];", + " if (a == b) return a;", + " for (int i = 32; i >= 0; i--)", + " if (fa[i][a] != fa[i][b]) a = fa[i][a], b = fa[i][b];", + " return fa[0][a];", + " }", + "};", + "" + ] + }, + "Class_Graph_erfen": { + "prefix": "Class_Graph_erfen", + "body": [ + "", + "class erfen_graph {", + " public:", + " ll res, n;", + " vi match, st;", + " Graph g;", + " erfen_graph(Graph g) {", + " this->g = g, this->n = g.n;", + " st = vector(n + 1), match = vector(n + 1);", + " res = 0;", + " for (int i = 1; i <= n; i++) {", + " st = vector(n + 1);", + " if (find(i)) res++;", + " }", + " }", + "", + " bool find(int u) {", + " for (int i = head[u]; ~i; i = e[i].next) {", + " if (!st[e[i].to]) {", + " st[e[i].to] = true;", + " if (!match[e[i].to] || find(match[e[i].to])) {", + " match[e[i].to] = u;", + " return true;", + " }", + " }", + " }", + " return false;", + " }", + "};", + "" + ] + } +} diff --git a/snippets/c/acm/Class_Math.code-snippets b/snippets/c/acm/Class_Math.code-snippets new file mode 100644 index 0000000..685c88e --- /dev/null +++ b/snippets/c/acm/Class_Math.code-snippets @@ -0,0 +1,108 @@ +{ + "Math_QuickPow": { + "prefix": "Math_QuickPow", + "body": [ + "", + "ll quick_Pow(ll a, ll b, ll mod) {", + " // a的b次方模mod", + " ll res = 1, t = a;", + " while (b) {", + " if (b & 1) res = (res * t) % mod;", + " t = t * t % mod;", + " b >>= 1;", + " }", + " return res;", + "}", + "", + ], + }, + "Math_Fm": { + "prefix": "Math_Fm", + "body": [ + "", + "ll quick_Pow(ll a, ll b, ll mod) {", + " // a的b次方模mod", + " ll res = 1, t = a;", + " while (b) {", + " if (b & 1) res = (res * t) % mod;", + " t = t * t % mod;", + " b >>= 1;", + " }", + " return res;", + "}", + "", + "ll Fm(ll a, ll mod) {", + " //费马小定理求逆元", + " return quick_Pow(a, mod - 2, mod);", + "}", + "", + ], + }, + "Math_C": { + "prefix": "Math_C", + "body": [ + "", + "ll quick_Pow(ll a, ll b, ll mod) {", + " // a的b次方模mod", + " ll res = 1, t = a;", + " while (b) {", + " if (b & 1) res = (res * t) % mod;", + " t = t * t % mod;", + " b >>= 1;", + " }", + " return res;", + "}", + "", + "ll Fm(ll a, ll mod) {", + " //费马小定理求逆元", + " return quick_Pow(a, mod - 2, mod);", + "}", + "", + "ll C(ll n, ll m, ll mod) {", + " ll fz = 1, fm = 1;", + " for (ll i = n; i >= n - m + 1; i--) fz = fz * i % mod;", + " for (ll i = 1; i <= m; i++) fm = fm * i % mod;", + " return (fz * Fm(fm, mod)) % mod;", + "}", + "", + ], + }, + "Class_Math_Bignum": { + "prefix": "Class_Math_Bignum", + "body": [ + "", + "class Math_Bignum {", + " public:", + " string Bignum;", + "", + " vll num;", + "", + " Math_Bignum(string s) {", + " Bignum = s;", + " for (auto i : s) num.push_back(i - '0');", + " }", + "", + " Math_Bignum(vll v) {", + " string s;", + " num = v;", + " for (auto i : v) s.push_back(i + '0');", + " }", + "", + " Math_Bignum(ll l) {", + " string s;", + " while (l) s.push_back(l % 10 + '0'), num.push_back(l % 10), l /= 10;", + " reverse(num.begin(), num.end());", + " reverse(s.begin(), s.end());", + " Bignum = s;", + " }", + "", + " ll get(ll l, ll r) {", + " ll res = 0;", + " for (int i = l - 1; i <= r - 1; i++) res = res * 10 + num[i];", + " return res;", + " }", + "};", + "", + ], + }, +} \ No newline at end of file diff --git a/snippets/go.json b/snippets/go.json new file mode 100644 index 0000000..79edb5b --- /dev/null +++ b/snippets/go.json @@ -0,0 +1,43 @@ +{ + "class": { + "prefix": "class", + "body": "type $1 struct{$2}\n$0" + }, + "errnil": { + "prefix": "errnil", + "body": [ + "if err != nil {", + " $1", + "}" + ] + }, + "init": { + "prefix": "init", + "body": [ + "func init() {", + " $1", + "}" + ] + }, + "ctx": { + "prefix": "ctx", + "body": [ + "ctx := context.Background()" + ] + }, + "cok": { + "prefix": "cok", + "body": [ + "c.JSON(http.StatusOK, vo.Success($1))" + ] + }, + "cbad": { + "prefix": "cbad", + "body": [ + "if err != nil {", + " c.JSON(http.StatusBadRequest, vo.Fail(err))", + " return", + "}" + ] + } +} diff --git a/snippets/json.json b/snippets/json.json new file mode 100644 index 0000000..59098d5 --- /dev/null +++ b/snippets/json.json @@ -0,0 +1,13 @@ +{ + "mod": { + "prefix": "mod", + "body": [ + " \"$1\": {", + " \"prefix\": \"$1\",", + " \"body\": [", + " $2", + " ]", + " }" + ] + } +} diff --git a/snippets/lua.json b/snippets/lua.json new file mode 100644 index 0000000..0db3279 --- /dev/null +++ b/snippets/lua.json @@ -0,0 +1,3 @@ +{ + +} From 94274b126a9eeede0895d429eec488d4a35e9427 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Wed, 10 Jun 2026 21:59:29 +0800 Subject: [PATCH 02/29] refactor: fix bugs, dedup :R, cleanup dead code, enable ufo+go.nvim, unify capabilities --- init.lua | 48 ++++++++++++++---------------------- lua/G.lua | 8 ++++++ lua/lsp/basedpyright.lua | 10 ++------ lua/lsp/bash.lua | 9 ++----- lua/lsp/c.lua | 9 ++----- lua/lsp/go.lua | 17 +++---------- lua/lsp/json.lua | 3 +-- lua/lsp/markdown.lua | 2 -- lua/lsp/pyright.lua | 11 --------- lua/options.lua | 7 ------ lua/plugs.lua | 23 ----------------- lua/plugs/dev.lua | 29 +++++++++++----------- lua/plugs/edit-plugs.lua | 27 ++++++++++++-------- lua/plugs/nvim-lspconfig.lua | 16 ++++++------ lua/plugs/theme.lua | 4 +-- lua/vsc.lua | 1 - 16 files changed, 77 insertions(+), 147 deletions(-) delete mode 100644 lua/lsp/markdown.lua delete mode 100644 lua/lsp/pyright.lua diff --git a/init.lua b/init.lua index 8bb8747..45c6006 100644 --- a/init.lua +++ b/init.lua @@ -1,9 +1,8 @@ G = require('G') +-- Clone lazy.nvim (only needed for native Neovim, not VSCode) if not G.g.vscode then - local lazypath = G.fn.stdpath("data") .. "/lazy/lazy.nvim" - if not G.loop.fs_stat(lazypath) then G.fn.system({ "git", @@ -13,34 +12,23 @@ if not G.g.vscode then "--branch=stable", lazypath, }) - - - G.fn.system({ - "git", - "config", - "--global", - "credential.helper", - "store", - }) end - G.opt.rtp:prepend(lazypath) - - require("keymap") - - - if G.g.vscode then - require('vscode') - else - require("options") - local clone_prefix = G.use_ssh and "git@github.com:%s.git" or "https://github.com/%s.git" - require("lazy").setup( - require('plugs'), { - lockfile = G.fn.stdpath("data") .. "/lazy/lazy-lock.json", - git = { - url_format = clone_prefix, - } - } - ) - end +end + +require("keymap") + +if G.g.vscode then + require('vscode') +else + require("options") + local clone_prefix = G.use_ssh and "git@github.com:%s.git" or "https://github.com/%s.git" + require("lazy").setup( + require('plugs'), { + lockfile = G.fn.stdpath("data") .. "/lazy/lazy-lock.json", + git = { + url_format = clone_prefix, + } + } + ) end diff --git a/lua/G.lua b/lua/G.lua index 6fe8152..0590f0a 100644 --- a/lua/G.lua +++ b/lua/G.lua @@ -54,6 +54,14 @@ function G.au(even, opts) return G.api.nvim_create_autocmd(even, opts) end +function G.run_cmd(cmd) + return function() + G.cmd [[set splitbelow | sp]] + G.cmd("term " .. cmd) + G.cmd [[resize 10 | startinsert]] + end +end + G.g.mapleader = ' ' return G diff --git a/lua/lsp/basedpyright.lua b/lua/lsp/basedpyright.lua index 3be769f..ebe6bad 100644 --- a/lua/lsp/basedpyright.lua +++ b/lua/lsp/basedpyright.lua @@ -1,5 +1,5 @@ return { - -- capabilities = require("cmp_nvim_lsp").default_capabilities(), + capabilities = require("cmp_nvim_lsp").default_capabilities(), settings = { basedpyright = { analysis = { @@ -11,12 +11,6 @@ return { }, }, on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term python3 %]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('python3 %'), {}) end } diff --git a/lua/lsp/bash.lua b/lua/lsp/bash.lua index 74c9c6a..e6ef83f 100644 --- a/lua/lsp/bash.lua +++ b/lua/lsp/bash.lua @@ -1,11 +1,6 @@ return{ + capabilities = require('cmp_nvim_lsp').default_capabilities(), on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term sh %]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('sh %'), {}) end } diff --git a/lua/lsp/c.lua b/lua/lsp/c.lua index b34d457..9ebefd4 100644 --- a/lua/lsp/c.lua +++ b/lua/lsp/c.lua @@ -1,11 +1,6 @@ return { + capabilities = require('cmp_nvim_lsp').default_capabilities(), on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term g++ "%" -o "%<" && ./"%<" && rm "%<"]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('g++ "%" -o "%<" && ./"%<" && rm "%<"'), {}) end } diff --git a/lua/lsp/go.lua b/lua/lsp/go.lua index 4b7eef4..07b3d3a 100644 --- a/lua/lsp/go.lua +++ b/lua/lsp/go.lua @@ -1,18 +1,7 @@ return { + capabilities = require('cmp_nvim_lsp').default_capabilities(), on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term go run %]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) - G.api.nvim_create_user_command('Rgin', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term go run ./main.go]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) + G.api.nvim_create_user_command('R', G.run_cmd('go run %'), {}) + G.api.nvim_create_user_command('Rgin', G.run_cmd('go run ./main.go'), {}) end } diff --git a/lua/lsp/json.lua b/lua/lsp/json.lua index a6cd7dd..1ee1daf 100644 --- a/lua/lsp/json.lua +++ b/lua/lsp/json.lua @@ -1,4 +1,3 @@ return { - on_attach = function() - end + capabilities = require('cmp_nvim_lsp').default_capabilities(), } diff --git a/lua/lsp/markdown.lua b/lua/lsp/markdown.lua deleted file mode 100644 index 97aeadd..0000000 --- a/lua/lsp/markdown.lua +++ /dev/null @@ -1,2 +0,0 @@ -return { -} diff --git a/lua/lsp/pyright.lua b/lua/lsp/pyright.lua deleted file mode 100644 index d0898f9..0000000 --- a/lua/lsp/pyright.lua +++ /dev/null @@ -1,11 +0,0 @@ -return { - on_attach = function() - G.api.nvim_create_user_command('R', function() - G.cmd [[set splitbelow]] - G.cmd [[sp]] - G.cmd [[term python3 %]] - G.cmd [[resize 10]] - G.cmd [[startinsert]] - end, {}) - end -} diff --git a/lua/options.lua b/lua/options.lua index 1a7ef51..b20cf55 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -63,13 +63,6 @@ G.au({ "VimEnter", "BufEnter" }, { end, }) --- G.au({ --- {"CmdlineEnter"}, --- { --- if index --- } --- }) - local function isempty(s) return s == nil or s == "" diff --git a/lua/plugs.lua b/lua/plugs.lua index 586ff2b..dda8cb2 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -6,27 +6,4 @@ return { require("plugs.edit-plugs"), require("plugs.dev"), - - -- leetcode刷题 - -- { - -- "kawre/leetcode.nvim", - -- build = ":TSUpdate html", - -- dependencies = { - -- "nvim-telescope/telescope.nvim", - -- "nvim-lua/plenary.nvim", -- telescope 所需 - -- "MunifTanjim/nui.nvim", - - -- -- 可选 - -- "nvim-treesitter/nvim-treesitter", - -- "rcarriga/nvim-notify", - -- "nvim-tree/nvim-web-devicons", - -- }, - -- opts = { - -- -- 配置放在这里 - -- cn = { - -- enabled = true, - -- }, - -- }, - -- }, - } diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua index e332706..58e242b 100644 --- a/lua/plugs/dev.lua +++ b/lua/plugs/dev.lua @@ -8,21 +8,20 @@ return { -- }) -- end -- }, - -- { - -- -- go开发 - -- "ray-x/go.nvim", - -- dependencies = { -- optional packages - -- "ray-x/guihua.lua", - -- "neovim/nvim-lspconfig", - -- "nvim-treesitter/nvim-treesitter", - -- }, - -- config = function() - -- require("go").setup() - -- end, - -- -- event = { "CmdlineEnter" }, - -- ft = { "go", 'gomod' }, - -- build = ':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries - -- }, + { + -- go开发 + "ray-x/go.nvim", + dependencies = { + "ray-x/guihua.lua", + "neovim/nvim-lspconfig", + "nvim-treesitter/nvim-treesitter", + }, + ft = { "go", 'gomod' }, + build = ':lua require("go.install").update_all_sync()', + config = function() + require("go").setup() + end, + }, { -- conda 环境 "kmontocam/nvim-conda", diff --git a/lua/plugs/edit-plugs.lua b/lua/plugs/edit-plugs.lua index d7fe61b..0fd3ac2 100644 --- a/lua/plugs/edit-plugs.lua +++ b/lua/plugs/edit-plugs.lua @@ -44,16 +44,23 @@ return { }) end }, - -- { - -- 'kevinhwang91/nvim-ufo', - -- dependencies = { - -- 'kevinhwang91/promise-async' - -- }, - -- config = function () - -- require("ufo").setup() - -- end - - -- }, + { + 'kevinhwang91/nvim-ufo', + dependencies = { + 'kevinhwang91/promise-async' + }, + config = function() + vim.opt.foldcolumn = '0' + vim.opt.foldlevel = 99 + vim.opt.foldlevelstart = 99 + vim.opt.foldenable = true + require("ufo").setup({ + provider_selector = function(bufnr, filetype, buftype) + return { 'treesitter', 'indent' } + end + }) + end + }, { -- hop "phaazon/hop.nvim", diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua index 9edd0b6..8df7e24 100644 --- a/lua/plugs/nvim-lspconfig.lua +++ b/lua/plugs/nvim-lspconfig.lua @@ -4,6 +4,7 @@ return { "neovim/nvim-lspconfig", dependencies = { "folke/neodev.nvim", + "hrsh7th/cmp-nvim-lsp", }, config = function() require 'neodev'.setup {} @@ -270,8 +271,7 @@ return { }, indent = { enable = true }, ignore_install = { - "txt", - "go" + "txt" }, sync_install = false, auto_install = true, @@ -287,21 +287,21 @@ return { additional_vim_regex_highlighting = false, }, parsers = { - html = { + vue = { install_info = { url = "https://github.com/ikatyang/tree-sitter-vue", files = { "src/parser.c" }, - branch = "main" - } - } - } + branch = "main", + }, + }, + }, } require 'nvim-treesitter'.setup(treesitter_opt) require 'nvim-treesitter.install'.prefer_git = true if G.use_ssh then local parsers = require 'nvim-treesitter.parsers'.get_parser_configs() for _, p in pairs(parsers) do - p.install_info.url = p.install_info.url:gsub("https://github/com/", "git@github.com:") + p.install_info.url = p.install_info.url:gsub("https://github.com/", "git@github.com:") end end end diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua index 013bed5..badc411 100644 --- a/lua/plugs/theme.lua +++ b/lua/plugs/theme.lua @@ -72,11 +72,11 @@ return { modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified show_tabs_only = false, -- this shows only tabs instead of tabs + buffers }, - G.cmd [[ + } + G.cmd [[ set guioptions-=e " Use showtabline in gui vim set sessionoptions+=tabpages,globals " store tabpages and globals in session ]] - } end, }, } diff --git a/lua/vsc.lua b/lua/vsc.lua index 0abf89d..f76df1f 100644 --- a/lua/vsc.lua +++ b/lua/vsc.lua @@ -1,4 +1,3 @@ require 'lazy'.setup({ require('plugs.edit-plugs'), - -- 'vijaymarupudi/nvim-fzf', -- fzf }) From 4acadc3ae4e43a024f33e1647012b0309c20d79e Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Wed, 10 Jun 2026 22:58:26 +0800 Subject: [PATCH 03/29] refactor: go.nvim build checks for go binary before installing tools --- lua/plugs/dev.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua index 58e242b..6d6fe05 100644 --- a/lua/plugs/dev.lua +++ b/lua/plugs/dev.lua @@ -17,7 +17,11 @@ return { "nvim-treesitter/nvim-treesitter", }, ft = { "go", 'gomod' }, - build = ':lua require("go.install").update_all_sync()', + build = function() + if vim.fn.executable('go') == 1 then + require("go.install").update_all_sync() + end + end, config = function() require("go").setup() end, From f1ed06ae9f6ac35519fdac5e02d07301efc698e6 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 10:12:48 +0800 Subject: [PATCH 04/29] refactor: split nvim-lspconfig into 6 modules, change rename to --- lua/plugs.lua | 11 +- lua/plugs/mason.lua | 29 ++++ lua/plugs/nvim-cmp.lua | 107 ++++++++++++ lua/plugs/nvim-lspconfig.lua | 316 +--------------------------------- lua/plugs/symbols-outline.lua | 74 ++++++++ lua/plugs/treesitter.lua | 53 ++++++ lua/plugs/winbar.lua | 40 +++++ 7 files changed, 311 insertions(+), 319 deletions(-) create mode 100644 lua/plugs/mason.lua create mode 100644 lua/plugs/nvim-cmp.lua create mode 100644 lua/plugs/symbols-outline.lua create mode 100644 lua/plugs/treesitter.lua create mode 100644 lua/plugs/winbar.lua diff --git a/lua/plugs.lua b/lua/plugs.lua index dda8cb2..7467c69 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -1,9 +1,12 @@ return { - require('plugs.nvim-lspconfig'), - require('plugs.nvimtree'), -- nvimtree - require('plugs.theme'), -- theme + require('plugs.mason'), + require('plugs.symbols-outline'), + require('plugs.nvim-cmp'), + require('plugs.treesitter'), + require('plugs.winbar'), + require('plugs.nvimtree'), + require('plugs.theme'), require("plugs.edit-plugs"), require("plugs.dev"), - } diff --git a/lua/plugs/mason.lua b/lua/plugs/mason.lua new file mode 100644 index 0000000..019c3e1 --- /dev/null +++ b/lua/plugs/mason.lua @@ -0,0 +1,29 @@ +return { + { + -- lsp 下载器 + "williamboman/mason-lspconfig.nvim", + dependencies = { + "williamboman/mason.nvim", + }, + config = function() + require "mason".setup { + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } + } + require("mason-lspconfig").setup({ + ensure_installed = { + "bashls", + -- "basedpyright", + "lua_ls", + "jsonls", + "yamlls", + } + }) + end + }, +} diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua new file mode 100644 index 0000000..a756d85 --- /dev/null +++ b/lua/plugs/nvim-cmp.lua @@ -0,0 +1,107 @@ +return { + { + -- lsp补全 + "hrsh7th/nvim-cmp", + dependencies = { + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + { + 'hrsh7th/vim-vsnip', + config = function() + G.g.vsnip_snippet_dir = G.fn.stdpath("config") .. "/snippets" + end + }, + 'hrsh7th/cmp-vsnip', + 'onsails/lspkind-nvim', + }, + config = function() + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(G.api.nvim_win_get_cursor(0)) + return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil + end + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + local cmp = require('cmp') + local cmp_opt = { + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + }, + { name = 'buffer' }, + { name = 'path' } + ), + mapping = cmp.mapping.preset.insert({ + + [""] = cmp.mapping({ + i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + c = function(fallback) + if cmp.visible() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) + else + fallback() + end + end, + }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + + }), + + window = { + completion = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + col_offset = -3, + side_padding = 0, + border = "rounded", + scrollbar = false, + }, + documentation = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", + border = "rounded", + scrollbar = false, + }, + }, + + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50, })(entry, vim_item) + local strings = vim.split(kind.kind, "%s", { trimempty = true }) + kind.kind = " " .. (strings[1] or "") .. " " + kind.menu = " (" .. (strings[2] or "") .. ")" + return kind + end, + }, + } + require('cmp').setup(cmp_opt) + end, + }, +} diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua index 8df7e24..2c46d6a 100644 --- a/lua/plugs/nvim-lspconfig.lua +++ b/lua/plugs/nvim-lspconfig.lua @@ -9,7 +9,6 @@ return { config = function() require 'neodev'.setup {} - -- 定义需要启用的服务器列表及其对应的配置 local servers = { lua_ls = require('lsp.lua'), clangd = require('lsp.c'), @@ -20,332 +19,19 @@ return { jsonls = require('lsp.json'), } - -- 使用 Neovim 0.11+ 的新 API 进行配置和启用 for server, config in pairs(servers) do vim.lsp.config(server, config) vim.lsp.enable(server) end - -- require 'lspconfig'.lua_ls.setup(require('lsp.lua')) - -- require 'lspconfig'.clangd.setup(require('lsp.c')) - -- require 'lspconfig'.bashls.setup(require('lsp.bash')) - -- require 'lspconfig'.basedpyright.setup(require('lsp.basedpyright')) - -- require 'lspconfig'.yamlls.setup(require('lsp.yaml')) - -- require 'lspconfig'.gopls.setup(require('lsp.go')) - -- require 'lspconfig'.jsonls.setup(require('lsp.json')) - G.map({ - - { 'n', 'rn', 'lua vim.lsp.buf.rename()' }, - + { 'n', '', 'lua vim.lsp.buf.rename()' }, { 'n', 'gd', 'lua vim.lsp.buf.definition()' }, { 'n', 'gh', 'lua vim.lsp.buf.hover()' }, { 'n', 'gD', 'lua vim.lsp.buf.declaration()' }, { 'n', 'gi', 'lua vim.lsp.buf.implementation()' }, { 'n', 'gr', 'lua vim.lsp.buf.references()' }, { 'n', '', 'lua vim.lsp.buf.format()' }, - - }) - end - - }, - { - -- lsp - "williamboman/mason-lspconfig.nvim", - dependencies = { - "williamboman/mason.nvim", -- lsp 下载器 - }, - config = function() - require "mason".setup { - ui = { - icons = { - package_installed = "✓", - package_pending = "➜", - package_uninstalled = "✗" - } - } - } - require("mason-lspconfig").setup({ - ensure_installed = { - "bashls", - -- "basedpyright", - "lua_ls", - "jsonls", - "yamlls", - } - }) - end - }, - { -- - 'simrat39/symbols-outline.nvim', - config = function() - local opts = { - highlight_hovered_item = true, - show_guides = true, - auto_preview = false, - position = 'right', - relative_width = true, - width = 25, - auto_close = false, - show_numbers = false, - show_relative_numbers = false, - show_symbol_details = true, - preview_bg_highlight = 'Pmenu', - autofold_depth = nil, - auto_unfold_hover = true, - fold_markers = { '', '' }, - wrap = false, - keymaps = { -- These keymaps can be a string or a table for multiple keys - close = { "", "q" }, - goto_location = "", - focus_location = "h", - hover_symbol = "", - toggle_preview = "K", - rename_symbol = "r", - code_actions = "a", - fold = "o", - unfold = "l", - fold_all = "W", - unfold_all = "E", - fold_reset = "R", - }, - lsp_blacklist = {}, - symbol_blacklist = {}, - symbols = { - File = { icon = "", hl = "@text.uri" }, - Module = { icon = "", hl = "@namespace" }, - Namespace = { icon = "", hl = "@namespace" }, - Package = { icon = "", hl = "@namespace" }, - Class = { icon = "𝓒", hl = "@type" }, - Method = { icon = "ƒ", hl = "@method" }, - Property = { icon = "", hl = "@method" }, - Field = { icon = "", hl = "@field" }, - Constructor = { icon = "", hl = "@constructor" }, - Enum = { icon = "ℰ", hl = "@type" }, - Interface = { icon = "ﰮ", hl = "@type" }, - Function = { icon = "", hl = "@function" }, - Variable = { icon = "", hl = "@constant" }, - Constant = { icon = "", hl = "@constant" }, - String = { icon = "𝓐", hl = "@string" }, - Number = { icon = "#", hl = "@number" }, - Boolean = { icon = "⊨", hl = "@boolean" }, - Array = { icon = "", hl = "@constant" }, - Object = { icon = "⦿", hl = "@type" }, - Key = { icon = "🔐", hl = "@type" }, - Null = { icon = "NULL", hl = "@type" }, - EnumMember = { icon = "", hl = "@field" }, - Struct = { icon = "𝓢", hl = "@type" }, - Event = { icon = "🗲", hl = "@type" }, - Operator = { icon = "+", hl = "@operator" }, - TypeParameter = { icon = "𝙏", hl = "@parameter" }, - Component = { icon = "", hl = "@function" }, - Fragment = { icon = "", hl = "@constant" }, - }, - } - require("symbols-outline").setup(opts) - G.map({ - { "n", "", "SymbolsOutline", { noremap = true } }, - }) - end - }, - { - -- lsp补全 - { - "hrsh7th/nvim-cmp", - dependencies = { - 'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' } - 'hrsh7th/cmp-buffer', -- { name = 'buffer' }, - 'hrsh7th/cmp-path', -- { name = 'path' } - 'hrsh7th/cmp-cmdline', -- { name = 'cmdline' } - { - 'hrsh7th/vim-vsnip', - config = function() - G.g.vsnip_snippet_dir = G.fn.stdpath("config") .. "/snippets" - end - }, - 'hrsh7th/cmp-vsnip', - 'onsails/lspkind-nvim', - }, - config = function() - local has_words_before = function() - unpack = unpack or table.unpack - local line, col = unpack(G.api.nvim_win_get_cursor(0)) - return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil - end - - local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) - end - local cmp = require('cmp') - local cmp_opt = { - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - end, - }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'vsnip' }, - }, - { name = 'buffer' }, - { name = 'path' } - ), - mapping = cmp.mapping.preset.insert({ - - [""] = cmp.mapping({ - i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), - c = function(fallback) - if cmp.visible() then - cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) - else - fallback() - end - end, - }), - - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif vim.fn["vsnip#available"](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - - [""] = cmp.mapping(function() - if cmp.visible() then - cmp.select_prev_item() - elseif vim.fn["vsnip#jumpable"](-1) == 1 then - feedkey("(vsnip-jump-prev)", "") - end - end, { "i", "s" }), - - }), - - window = { - completion = { - winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", - col_offset = -3, - side_padding = 0, - border = "rounded", - scrollbar = false, - }, - documentation = { - winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None", - border = "rounded", - scrollbar = false, - }, - }, - - formatting = { - fields = { "kind", "abbr", "menu" }, - format = function(entry, vim_item) - local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50, })(entry, vim_item) - local strings = vim.split(kind.kind, "%s", { trimempty = true }) - kind.kind = " " .. (strings[1] or "") .. " " - kind.menu = " (" .. (strings[2] or "") .. ")" - return kind - end, - }, - } - require('cmp').setup(cmp_opt) - end, - }, - - { - -- 语法高亮 -- - 'nvim-treesitter/nvim-treesitter', - config = function() - local treesitter_opt = { - ensure_installed = { - -- "c", - -- "cpp", - -- "python", - -- "java", - -- "lua", - -- "bash", - -- "vimdoc", - }, - indent = { enable = true }, - ignore_install = { - "txt" - }, - sync_install = false, - auto_install = true, - highlight = { - enable = true, - disable = function(_, buf) - local max_filesize = 100 * 1024 -- 100 KB - local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) - if ok and stats and stats.size > max_filesize then - return true - end - end, - additional_vim_regex_highlighting = false, - }, - parsers = { - vue = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-vue", - files = { "src/parser.c" }, - branch = "main", - }, - }, - }, - } - require 'nvim-treesitter'.setup(treesitter_opt) - require 'nvim-treesitter.install'.prefer_git = true - if G.use_ssh then - local parsers = require 'nvim-treesitter.parsers'.get_parser_configs() - for _, p in pairs(parsers) do - p.install_info.url = p.install_info.url:gsub("https://github.com/", "git@github.com:") - end - end - end - }, - }, - { - 'fgheng/winbar.nvim', - config = function() - require('winbar').setup({ - enabled = true, -- 是否启动winbar - - -- show_file_path = true, -- 是否显示文件路径 - show_symbols = true, -- 是否显示函数标签 - - -- 颜色配置,为空,将使用默认配色 - colors = { - path = '#aaffff', -- 路径的颜色,比如#ababab - file_name = '#bbbbff', -- 文件名称的颜色,比如#acacac - symbols = '#aaffaa', -- 函数颜色 - }, - - -- 图标配置 - icons = { - seperator = '>', -- 路径分割符号 - editor_state = '●', - lock_icon = '', - }, - - -- 关闭winbar的窗口 - exclude_filetype = { - 'help', - 'startify', - 'dashboard', - 'packer', - 'neogitstatus', - 'NvimTree', - 'Trouble', - 'alpha', - 'lir', - 'Outline', - 'spectre_panel', - 'toggleterm', - 'qf', - } }) end }, diff --git a/lua/plugs/symbols-outline.lua b/lua/plugs/symbols-outline.lua new file mode 100644 index 0000000..a4ce924 --- /dev/null +++ b/lua/plugs/symbols-outline.lua @@ -0,0 +1,74 @@ +return { + { -- + 'simrat39/symbols-outline.nvim', + config = function() + local opts = { + highlight_hovered_item = true, + show_guides = true, + auto_preview = false, + position = 'right', + relative_width = true, + width = 25, + auto_close = false, + show_numbers = false, + show_relative_numbers = false, + show_symbol_details = true, + preview_bg_highlight = 'Pmenu', + autofold_depth = nil, + auto_unfold_hover = true, + fold_markers = { '', '' }, + wrap = false, + keymaps = { + close = { "", "q" }, + goto_location = "", + focus_location = "h", + hover_symbol = "", + toggle_preview = "K", + rename_symbol = "r", + code_actions = "a", + fold = "o", + unfold = "l", + fold_all = "W", + unfold_all = "E", + fold_reset = "R", + }, + lsp_blacklist = {}, + symbol_blacklist = {}, + symbols = { + File = { icon = "", hl = "@text.uri" }, + Module = { icon = "", hl = "@namespace" }, + Namespace = { icon = "", hl = "@namespace" }, + Package = { icon = "", hl = "@namespace" }, + Class = { icon = "𝓒", hl = "@type" }, + Method = { icon = "ƒ", hl = "@method" }, + Property = { icon = "", hl = "@method" }, + Field = { icon = "", hl = "@field" }, + Constructor = { icon = "", hl = "@constructor" }, + Enum = { icon = "ℰ", hl = "@type" }, + Interface = { icon = "ﰮ", hl = "@type" }, + Function = { icon = "", hl = "@function" }, + Variable = { icon = "", hl = "@constant" }, + Constant = { icon = "", hl = "@constant" }, + String = { icon = "𝓐", hl = "@string" }, + Number = { icon = "#", hl = "@number" }, + Boolean = { icon = "⊨", hl = "@boolean" }, + Array = { icon = "", hl = "@constant" }, + Object = { icon = "⦿", hl = "@type" }, + Key = { icon = "🔐", hl = "@type" }, + Null = { icon = "NULL", hl = "@type" }, + EnumMember = { icon = "", hl = "@field" }, + Struct = { icon = "𝓢", hl = "@type" }, + Event = { icon = "🗲", hl = "@type" }, + Operator = { icon = "+", hl = "@operator" }, + TypeParameter = { icon = "𝙏", hl = "@parameter" }, + Component = { icon = "", hl = "@function" }, + Fragment = { icon = "", hl = "@constant" }, + }, + } + require("symbols-outline").setup(opts) + G.map({ + { "n", "", "SymbolsOutline", { noremap = true } }, + }) + end + }, +} diff --git a/lua/plugs/treesitter.lua b/lua/plugs/treesitter.lua new file mode 100644 index 0000000..e0056bb --- /dev/null +++ b/lua/plugs/treesitter.lua @@ -0,0 +1,53 @@ +return { + { + -- 语法高亮 -- + 'nvim-treesitter/nvim-treesitter', + config = function() + local treesitter_opt = { + ensure_installed = { + -- "c", + -- "cpp", + -- "python", + -- "java", + -- "lua", + -- "bash", + -- "vimdoc", + }, + indent = { enable = true }, + ignore_install = { + "txt" + }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + disable = function(_, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + additional_vim_regex_highlighting = false, + }, + parsers = { + vue = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = { "src/parser.c" }, + branch = "main", + }, + }, + }, + } + require 'nvim-treesitter'.setup(treesitter_opt) + require 'nvim-treesitter.install'.prefer_git = true + if G.use_ssh then + local parsers = require 'nvim-treesitter.parsers'.get_parser_configs() + for _, p in pairs(parsers) do + p.install_info.url = p.install_info.url:gsub("https://github.com/", "git@github.com:") + end + end + end + }, +} diff --git a/lua/plugs/winbar.lua b/lua/plugs/winbar.lua new file mode 100644 index 0000000..5798e0f --- /dev/null +++ b/lua/plugs/winbar.lua @@ -0,0 +1,40 @@ +return { + { + 'fgheng/winbar.nvim', + config = function() + require('winbar').setup({ + enabled = true, + + show_symbols = true, + + colors = { + path = '#aaffff', + file_name = '#bbbbff', + symbols = '#aaffaa', + }, + + icons = { + seperator = '>', + editor_state = '●', + lock_icon = '', + }, + + exclude_filetype = { + 'help', + 'startify', + 'dashboard', + 'packer', + 'neogitstatus', + 'NvimTree', + 'Trouble', + 'alpha', + 'lir', + 'Outline', + 'spectre_panel', + 'toggleterm', + 'qf', + } + }) + end + }, +} From cbf457999028cb81a076e68e5d080a03417522a6 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 11:53:18 +0800 Subject: [PATCH 05/29] refactor: fix medium-severity issues (lazy leak, formatoptions, dupe map, dead opts, split theme, cmp keys, capabilities injection, typos, style) --- init.lua | 36 +++++++------- lua/G.lua | 1 - lua/keymap.lua | 4 -- lua/lsp/basedpyright.lua | 1 - lua/lsp/bash.lua | 1 - lua/lsp/c.lua | 1 - lua/lsp/go.lua | 1 - lua/lsp/json.lua | 4 +- lua/lsp/lua.lua | 2 - lua/lsp/yaml.lua | 1 - lua/options.lua | 12 +---- lua/plugs.lua | 4 +- lua/plugs/edit-plugs.lua | 31 +++++------- lua/plugs/nvim-cmp.lua | 10 ++-- lua/plugs/nvim-lspconfig.lua | 2 + lua/plugs/nvimtree.lua | 5 +- lua/plugs/symbols-outline.lua | 2 +- lua/plugs/theme.lua | 36 ++++++-------- lua/plugs/treesitter.lua | 9 ---- lua/plugs/winbar.lua | 2 +- snippets/lua.json | 90 ++++++++++++++++++++++++++++++++++- 21 files changed, 149 insertions(+), 106 deletions(-) diff --git a/init.lua b/init.lua index 45c6006..96411f5 100644 --- a/init.lua +++ b/init.lua @@ -1,31 +1,29 @@ G = require('G') --- Clone lazy.nvim (only needed for native Neovim, not VSCode) -if not G.g.vscode then - local lazypath = G.fn.stdpath("data") .. "/lazy/lazy.nvim" - if not G.loop.fs_stat(lazypath) then - G.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) - end - G.opt.rtp:prepend(lazypath) +-- 安装/定位 lazy.nvim(VSCode 和原生 Neovim 都需要) +local lazypath = G.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not G.loop.fs_stat(lazypath) then + G.fn.system({ + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', + lazypath, + }) end +G.opt.rtp:prepend(lazypath) -require("keymap") +require('keymap') if G.g.vscode then require('vscode') else - require("options") - local clone_prefix = G.use_ssh and "git@github.com:%s.git" or "https://github.com/%s.git" - require("lazy").setup( + require('options') + local clone_prefix = G.use_ssh and 'git@github.com:%s.git' or 'https://github.com/%s.git' + require('lazy').setup( require('plugs'), { - lockfile = G.fn.stdpath("data") .. "/lazy/lazy-lock.json", + lockfile = G.fn.stdpath('data') .. '/lazy/lazy-lock.json', git = { url_format = clone_prefix, } diff --git a/lua/G.lua b/lua/G.lua index 0590f0a..17909a7 100644 --- a/lua/G.lua +++ b/lua/G.lua @@ -22,7 +22,6 @@ function G.map(maps) else print("太多变量了") end - --G.api.nvim_set_keymap(map[1], map[2], map[3], map[4]) end end diff --git a/lua/keymap.lua b/lua/keymap.lua index 9b04fd1..b5496b7 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -20,20 +20,16 @@ G.map({ { 'n', '', ':tabn', opt }, { 'n', '', ':tabp', opt }, - { 'n', '', 'j', opt }, { 'n', '', 'h', opt }, { 'n', '', 'k', opt }, { 'n', '', 'l', opt }, - { 'n', '', ':q', opt }, { 'n', '', ':w !sudo tee %', opt }, { 'n', '', ':q!', opt }, { 'v', '', '"+y', opt }, - - { 'n', 'y', 'ggyG', opt }, { 'n', 'p', 'ggpG', opt }, { 'n', 'v', 'ggVG', opt }, diff --git a/lua/lsp/basedpyright.lua b/lua/lsp/basedpyright.lua index ebe6bad..873421c 100644 --- a/lua/lsp/basedpyright.lua +++ b/lua/lsp/basedpyright.lua @@ -1,5 +1,4 @@ return { - capabilities = require("cmp_nvim_lsp").default_capabilities(), settings = { basedpyright = { analysis = { diff --git a/lua/lsp/bash.lua b/lua/lsp/bash.lua index e6ef83f..978ef55 100644 --- a/lua/lsp/bash.lua +++ b/lua/lsp/bash.lua @@ -1,5 +1,4 @@ return{ - capabilities = require('cmp_nvim_lsp').default_capabilities(), on_attach = function() G.api.nvim_create_user_command('R', G.run_cmd('sh %'), {}) end diff --git a/lua/lsp/c.lua b/lua/lsp/c.lua index 9ebefd4..3c006ed 100644 --- a/lua/lsp/c.lua +++ b/lua/lsp/c.lua @@ -1,5 +1,4 @@ return { - capabilities = require('cmp_nvim_lsp').default_capabilities(), on_attach = function() G.api.nvim_create_user_command('R', G.run_cmd('g++ "%" -o "%<" && ./"%<" && rm "%<"'), {}) end diff --git a/lua/lsp/go.lua b/lua/lsp/go.lua index 07b3d3a..e5d19ca 100644 --- a/lua/lsp/go.lua +++ b/lua/lsp/go.lua @@ -1,5 +1,4 @@ return { - capabilities = require('cmp_nvim_lsp').default_capabilities(), on_attach = function() G.api.nvim_create_user_command('R', G.run_cmd('go run %'), {}) G.api.nvim_create_user_command('Rgin', G.run_cmd('go run ./main.go'), {}) diff --git a/lua/lsp/json.lua b/lua/lsp/json.lua index 1ee1daf..a564707 100644 --- a/lua/lsp/json.lua +++ b/lua/lsp/json.lua @@ -1,3 +1 @@ -return { - capabilities = require('cmp_nvim_lsp').default_capabilities(), -} +return {} diff --git a/lua/lsp/lua.lua b/lua/lsp/lua.lua index fdd0fde..288722d 100644 --- a/lua/lsp/lua.lua +++ b/lua/lsp/lua.lua @@ -5,8 +5,6 @@ table.insert(runtime_path, "lua/?/init.lua") return { - capabilities = require('cmp_nvim_lsp').default_capabilities(), - settings = { Lua = { diff --git a/lua/lsp/yaml.lua b/lua/lsp/yaml.lua index 7990cc8..2bd9f59 100644 --- a/lua/lsp/yaml.lua +++ b/lua/lsp/yaml.lua @@ -1,5 +1,4 @@ return { - capabilities = require('cmp_nvim_lsp').default_capabilities(), settings = { yaml = { schemas = { diff --git a/lua/options.lua b/lua/options.lua index b20cf55..57456b7 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,4 +1,3 @@ --- G.opt.ttimeout = true G.opt.ttimeoutlen = 100 @@ -39,15 +38,8 @@ G.opt.wrap = false G.cmd("filetype plugin indent on") -- 取消换行注释 -G.au({ "BufEnter" }, { - pattern = { "*" }, - callback = function() - -- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" } - G.opt.formatoptions = G.opt.formatoptions - - "o" -- O and o, don't continue comments - + "r" -- But do continue when pressing enter. - end, -}) +G.opt.formatoptions = G.opt.formatoptions - "o" + "r" + G.au({ "InsertEnter" }, { pattern = { "*" }, diff --git a/lua/plugs.lua b/lua/plugs.lua index 7467c69..b0b2319 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -7,6 +7,6 @@ return { require('plugs.winbar'), require('plugs.nvimtree'), require('plugs.theme'), - require("plugs.edit-plugs"), - require("plugs.dev"), + require('plugs.edit-plugs'), + require('plugs.dev'), } diff --git a/lua/plugs/edit-plugs.lua b/lua/plugs/edit-plugs.lua index 0fd3ac2..a209b64 100644 --- a/lua/plugs/edit-plugs.lua +++ b/lua/plugs/edit-plugs.lua @@ -13,31 +13,27 @@ return { { 'terryma/vim-multiple-cursors', }, + --格式整理 { - --格式整理 - { - 'junegunn/vim-easy-align', - config = function() - G.map({ - { "v", "ga", ":EasyAlign", { noremap = true } }, - { "v", "=", ":EasyAlign", { noremap = true } }, - }) - end - }, - }, - { - -- 注释插件 - { - 'tpope/vim-commentary', - } + 'junegunn/vim-easy-align', + config = function() + G.map({ + { "v", "ga", ":EasyAlign", { noremap = true } }, + { "v", "=", ":EasyAlign", { noremap = true } }, + }) + end }, + -- 注释插件(neovim 0.12 内置 gc,用 treesitter,先注释测试) + -- { + -- 'tpope/vim-commentary', + -- }, { 'github/copilot.vim', -- github copilot + event = "InsertEnter", }, { 'windwp/nvim-autopairs', event = "InsertEnter", - opts = {}, -- this is equalent to setup({}) function config = function() require('nvim-autopairs').setup({ disable_filetype = { "vim" }, @@ -69,7 +65,6 @@ return { "f", "F", "t", "T", "" }, - lazy = true, config = function() require("hop").setup { keys = 'asdfghjkl;' } local hop = require('hop') diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua index a756d85..05f3d7b 100644 --- a/lua/plugs/nvim-cmp.lua +++ b/lua/plugs/nvim-cmp.lua @@ -18,7 +18,7 @@ return { }, config = function() local has_words_before = function() - unpack = unpack or table.unpack + local unpack = table.unpack local line, col = unpack(G.api.nvim_win_get_cursor(0)) return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil end @@ -43,17 +43,17 @@ return { mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping({ - i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }), c = function(fallback) if cmp.visible() then - cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) else fallback() end end, }), - [""] = cmp.mapping(function(fallback) + [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.fn["vsnip#available"](1) == 1 then @@ -65,7 +65,7 @@ return { end end, { "i", "s" }), - [""] = cmp.mapping(function() + [""] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#jumpable"](-1) == 1 then diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua index 2c46d6a..ddfb22d 100644 --- a/lua/plugs/nvim-lspconfig.lua +++ b/lua/plugs/nvim-lspconfig.lua @@ -19,7 +19,9 @@ return { jsonls = require('lsp.json'), } + local capabilities = require('cmp_nvim_lsp').default_capabilities() for server, config in pairs(servers) do + config.capabilities = capabilities vim.lsp.config(server, config) vim.lsp.enable(server) end diff --git a/lua/plugs/nvimtree.lua b/lua/plugs/nvimtree.lua index c2f2607..94c0729 100644 --- a/lua/plugs/nvimtree.lua +++ b/lua/plugs/nvimtree.lua @@ -1,7 +1,7 @@ return { "nvim-tree/nvim-tree.lua", dependencies = { - 'kyazdani42/nvim-web-devicons' + 'nvim-tree/nvim-web-devicons' }, keys = { "" @@ -33,8 +33,5 @@ return { }) end } - G.map({ - { "n", "", ":NvimTreeToggle", { noremap = true } }, - }) end } diff --git a/lua/plugs/symbols-outline.lua b/lua/plugs/symbols-outline.lua index a4ce924..3d481a9 100644 --- a/lua/plugs/symbols-outline.lua +++ b/lua/plugs/symbols-outline.lua @@ -20,7 +20,7 @@ return { wrap = false, keymaps = { close = { "", "q" }, - goto_location = "", + goto_location = "", focus_location = "h", hover_symbol = "", toggle_preview = "K", diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua index badc411..3e1428f 100644 --- a/lua/plugs/theme.lua +++ b/lua/plugs/theme.lua @@ -7,8 +7,7 @@ return { end }, { - -- line插件 - 'kdheepak/tabline.nvim', + -- 状态栏 'nvim-lualine/lualine.nvim', config = function() require('lualine').setup { @@ -17,10 +16,6 @@ return { theme = 'auto', component_separators = { left = '', right = '' }, section_separators = { left = '', right = '' }, - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, ignore_focus = {}, always_divide_middle = true, globalstatus = false, @@ -50,27 +45,26 @@ return { lualine_y = {}, lualine_z = {} }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} } + end, + }, + { + -- 标签栏 + 'kdheepak/tabline.nvim', + config = function() require('tabline').setup { - -- Defaults configuration options enable = true, options = { - -- If lualine is installed tabline will use separators configured in lualine by default. - -- These options can be used to override those settings. section_separators = { ' ', ' ' }, component_separators = { '', '' }, - max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 - show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named - show_devicons = true, -- this shows devicons in buffer section - show_bufnr = false, -- this appends [bufnr] to buffer section, - show_filename_only = true, -- shows base filename only instead of relative path in filename - modified_icon = "+ ", -- change the default modified icon - modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified - show_tabs_only = false, -- this shows only tabs instead of tabs + buffers + max_bufferline_percent = 66, + show_tabs_always = false, + show_devicons = true, + show_bufnr = false, + show_filename_only = true, + modified_icon = "+ ", + modified_italic = false, + show_tabs_only = false, }, } G.cmd [[ diff --git a/lua/plugs/treesitter.lua b/lua/plugs/treesitter.lua index e0056bb..4da2bfd 100644 --- a/lua/plugs/treesitter.lua +++ b/lua/plugs/treesitter.lua @@ -4,15 +4,6 @@ return { 'nvim-treesitter/nvim-treesitter', config = function() local treesitter_opt = { - ensure_installed = { - -- "c", - -- "cpp", - -- "python", - -- "java", - -- "lua", - -- "bash", - -- "vimdoc", - }, indent = { enable = true }, ignore_install = { "txt" diff --git a/lua/plugs/winbar.lua b/lua/plugs/winbar.lua index 5798e0f..3403186 100644 --- a/lua/plugs/winbar.lua +++ b/lua/plugs/winbar.lua @@ -14,7 +14,7 @@ return { }, icons = { - seperator = '>', + separator = '>', editor_state = '●', lock_icon = '', }, diff --git a/snippets/lua.json b/snippets/lua.json index 0db3279..21c64a7 100644 --- a/snippets/lua.json +++ b/snippets/lua.json @@ -1,3 +1,91 @@ { - + "plug": { + "prefix": "plug", + "body": [ + "{", + " '${1:owner/repo}',", + " config = function()", + " require('${2}').setup({$3})", + " end,", + "}," + ] + }, + "plugkey": { + "prefix": "plugkey", + "body": [ + "{", + " '${1:owner/repo}',", + " keys = { '${2}' },", + " config = function()", + " require('${3}').setup({$4})", + " end,", + "}," + ] + }, + "plugftp": { + "prefix": "plugftp", + "body": [ + "{", + " '${1:owner/repo}',", + " ft = { '${2}' },", + " config = function()", + " require('${3}').setup({$4})", + " end,", + "}," + ] + }, + "map": { + "prefix": "map", + "body": "{ '${1:n}', '${2:}', '${3:cmd}', { noremap = true } }," + }, + "mapl": { + "prefix": "mapl", + "body": [ + "{ '${1:n}', '${2:}',", + " function()", + " ${3}", + " end,", + " { noremap = true }", + "}," + ] + }, + "func": { + "prefix": "func", + "body": [ + "function ${1:name}(${2:args})", + " ${3}", + "end" + ] + }, + "localf": { + "prefix": "localf", + "body": [ + "local ${1:name} = function(${2:args})", + " ${3}", + "end" + ] + }, + "Gmap": { + "prefix": "Gmap", + "body": [ + "G.map({", + " { '${1:n}', '${2:}', '${3:cmd}', { noremap = true } },", + "})" + ] + }, + "req": { + "prefix": "req", + "body": "local ${1:name} = require('${1}')" + }, + "au": { + "prefix": "au", + "body": [ + "G.au({ '${1:BufEnter}' }, {", + " pattern = { '${2:*}' },", + " callback = function()", + " ${3}", + " end,", + "})" + ] + } } From 5261a7f2d7ba52c4fed50eedfa8435bbffe55aae Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 11:53:52 +0800 Subject: [PATCH 06/29] update --- nvim.log | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nvim.log diff --git a/nvim.log b/nvim.log new file mode 100644 index 0000000..74a5782 --- /dev/null +++ b/nvim.log @@ -0,0 +1,34 @@ +WRN 2026-06-10T23:07:04.742 ?.178813 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178813.0 +WRN 2026-06-10T23:07:14.503 ?.178830 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178830.0 +WRN 2026-06-10T23:07:20.258 ?.178843 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178843.0 +WRN 2026-06-10T23:07:31.294 ?.178860 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178860.0 +WRN 2026-06-10T23:07:36.038 ?.178871 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178871.0 +WRN 2026-06-10T23:19:27.309 ?.179580 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.179580.0 +WRN 2026-06-10T23:19:41.624 ?.179607 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.179607.0 +WRN 2026-06-11T09:51:38.881 ?.185506 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.185506.0 +WRN 2026-06-11T10:06:55.879 ?.186600 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186600.0 +WRN 2026-06-11T10:07:17.680 ?.186657 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186657.0 +WRN 2026-06-11T10:08:07.476 ?.186733 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186733.0 +WRN 2026-06-11T10:08:14.726 ?.186744 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186744.0 +WRN 2026-06-11T10:09:16.315 ?.186855 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186855.0 +WRN 2026-06-11T10:10:23.672 ?.186928 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186928.0 +WRN 2026-06-11T10:10:32.042 ?.186955 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186955.0 +WRN 2026-06-11T10:10:42.371 ?.186974 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186974.0 +WRN 2026-06-11T10:10:49.612 ?.186987 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186987.0 +WRN 2026-06-11T10:10:55.948 ?.187004 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187004.0 +WRN 2026-06-11T10:11:03.993 ?.187017 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187017.0 +WRN 2026-06-11T10:11:24.096 ?.187038 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187038.0 +WRN 2026-06-11T10:11:52.936 ?.187080 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187080.0 +WRN 2026-06-11T10:11:57.253 ?.187092 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187092.0 +WRN 2026-06-11T10:34:30.207 ?.191088 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.191088.0 +WRN 2026-06-11T10:34:30.260 ?.191091 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.191091.0 +WRN 2026-06-11T10:55:29.749 ?.192310 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192310.0 +WRN 2026-06-11T10:55:32.747 ?.192321 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192321.0 +WRN 2026-06-11T10:55:52.170 ?.192355 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192355.0 +WRN 2026-06-11T10:59:29.336 ?.192571 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192571.0 +WRN 2026-06-11T11:09:44.996 ?.193060 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.193060.0 +WRN 2026-06-11T11:14:25.729 ?.193304 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.193304.0 +WRN 2026-06-11T11:37:25.190 ?.194777 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.194777.0 +WRN 2026-06-11T11:49:18.648 ?.195438 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.195438.0 +WRN 2026-06-11T11:49:18.666 ?.195440 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.195440.0 +WRN 2026-06-11T11:52:22.961 ?.195636 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.195636.0 From 8c60f353f8a319d17d5841a7f0dd6e51c875b22f Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 12:00:49 +0800 Subject: [PATCH 07/29] fix: nvimtree keymap, add cmdline completion for cmp --- lua/plugs/nvim-cmp.lua | 18 ++++++++++++++++++ lua/plugs/nvimtree.lua | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua index 05f3d7b..d402872 100644 --- a/lua/plugs/nvim-cmp.lua +++ b/lua/plugs/nvim-cmp.lua @@ -102,6 +102,24 @@ return { }, } require('cmp').setup(cmp_opt) + + -- 命令栏补全 + require('cmp').setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'cmdline' }, + }, { + { name = 'path' }, + }) + }) + + -- 搜索栏补全 + require('cmp').setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' }, + } + }) end, }, } diff --git a/lua/plugs/nvimtree.lua b/lua/plugs/nvimtree.lua index 94c0729..53b7149 100644 --- a/lua/plugs/nvimtree.lua +++ b/lua/plugs/nvimtree.lua @@ -4,7 +4,7 @@ return { 'nvim-tree/nvim-web-devicons' }, keys = { - "" + { "", "NvimTreeToggle", desc = "Toggle file tree" } }, config = function() require 'nvim-web-devicons'.setup {} From dc82aa4ad859e4626e0a434be66d28a07525c4e8 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 12:04:58 +0800 Subject: [PATCH 08/29] fix: cmdline completion sources, gitignore nvim.log --- .gitignore | 1 + lua/plugs/nvim-cmp.lua | 7 +++---- nvim.log | 34 ---------------------------------- 3 files changed, 4 insertions(+), 38 deletions(-) delete mode 100644 nvim.log diff --git a/.gitignore b/.gitignore index e033bc6..47f5852 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ lazy-lock.json +nvim.log diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua index d402872..4e05e13 100644 --- a/lua/plugs/nvim-cmp.lua +++ b/lua/plugs/nvim-cmp.lua @@ -103,14 +103,13 @@ return { } require('cmp').setup(cmp_opt) - -- 命令栏补全 + -- 命令栏补全(Tab 导航,回车无选择时直接执行) require('cmp').setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ + sources = { { name = 'cmdline' }, - }, { { name = 'path' }, - }) + } }) -- 搜索栏补全 diff --git a/nvim.log b/nvim.log deleted file mode 100644 index 74a5782..0000000 --- a/nvim.log +++ /dev/null @@ -1,34 +0,0 @@ -WRN 2026-06-10T23:07:04.742 ?.178813 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178813.0 -WRN 2026-06-10T23:07:14.503 ?.178830 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178830.0 -WRN 2026-06-10T23:07:20.258 ?.178843 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178843.0 -WRN 2026-06-10T23:07:31.294 ?.178860 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178860.0 -WRN 2026-06-10T23:07:36.038 ?.178871 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.178871.0 -WRN 2026-06-10T23:19:27.309 ?.179580 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.179580.0 -WRN 2026-06-10T23:19:41.624 ?.179607 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.179607.0 -WRN 2026-06-11T09:51:38.881 ?.185506 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.185506.0 -WRN 2026-06-11T10:06:55.879 ?.186600 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186600.0 -WRN 2026-06-11T10:07:17.680 ?.186657 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186657.0 -WRN 2026-06-11T10:08:07.476 ?.186733 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186733.0 -WRN 2026-06-11T10:08:14.726 ?.186744 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186744.0 -WRN 2026-06-11T10:09:16.315 ?.186855 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186855.0 -WRN 2026-06-11T10:10:23.672 ?.186928 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186928.0 -WRN 2026-06-11T10:10:32.042 ?.186955 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186955.0 -WRN 2026-06-11T10:10:42.371 ?.186974 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186974.0 -WRN 2026-06-11T10:10:49.612 ?.186987 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.186987.0 -WRN 2026-06-11T10:10:55.948 ?.187004 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187004.0 -WRN 2026-06-11T10:11:03.993 ?.187017 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187017.0 -WRN 2026-06-11T10:11:24.096 ?.187038 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187038.0 -WRN 2026-06-11T10:11:52.936 ?.187080 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187080.0 -WRN 2026-06-11T10:11:57.253 ?.187092 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.187092.0 -WRN 2026-06-11T10:34:30.207 ?.191088 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.191088.0 -WRN 2026-06-11T10:34:30.260 ?.191091 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.191091.0 -WRN 2026-06-11T10:55:29.749 ?.192310 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192310.0 -WRN 2026-06-11T10:55:32.747 ?.192321 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192321.0 -WRN 2026-06-11T10:55:52.170 ?.192355 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192355.0 -WRN 2026-06-11T10:59:29.336 ?.192571 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.192571.0 -WRN 2026-06-11T11:09:44.996 ?.193060 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.193060.0 -WRN 2026-06-11T11:14:25.729 ?.193304 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.193304.0 -WRN 2026-06-11T11:37:25.190 ?.194777 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.194777.0 -WRN 2026-06-11T11:49:18.648 ?.195438 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.195438.0 -WRN 2026-06-11T11:49:18.666 ?.195440 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.195440.0 -WRN 2026-06-11T11:52:22.961 ?.195636 server_start:197: Failed to start server: read-only file system: /run/user/1000/nvim.195636.0 From 3bfbb680fb94c4c522a98fc45b3ce07d668c3f4c Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 15:21:18 +0800 Subject: [PATCH 09/29] fix: cmdline fallthrough when no selection --- lua/plugs/nvim-cmp.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua index 4e05e13..49076ad 100644 --- a/lua/plugs/nvim-cmp.lua +++ b/lua/plugs/nvim-cmp.lua @@ -105,7 +105,19 @@ return { -- 命令栏补全(Tab 导航,回车无选择时直接执行) require('cmp').setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), + mapping = { + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'c' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'c' }), + [''] = cmp.mapping({ + c = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ select = false }) + else + fallback() + end + end, + }), + }, sources = { { name = 'cmdline' }, { name = 'path' }, @@ -114,7 +126,19 @@ return { -- 搜索栏补全 require('cmp').setup.cmdline('/', { - mapping = cmp.mapping.preset.cmdline(), + mapping = { + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'c' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'c' }), + [''] = cmp.mapping({ + c = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ select = false }) + else + fallback() + end + end, + }), + }, sources = { { name = 'buffer' }, } From bc435e499eaf9d5c5f971d6aba49beebbf1307bf Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 15:28:19 +0800 Subject: [PATCH 10/29] fix: replace table.unpack with direct indexing for Neovim 0.12 compat --- lua/options.lua | 1 - lua/plugs/nvim-cmp.lua | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/options.lua b/lua/options.lua index 57456b7..d053a69 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -7,7 +7,6 @@ G.opt.rnu = true G.opt.scrolloff = 999 -- 自动保存 -G.opt.autowrite = true G.opt.autowriteall = true -- tab键 diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua index 49076ad..191a2e9 100644 --- a/lua/plugs/nvim-cmp.lua +++ b/lua/plugs/nvim-cmp.lua @@ -18,8 +18,8 @@ return { }, config = function() local has_words_before = function() - local unpack = table.unpack - local line, col = unpack(G.api.nvim_win_get_cursor(0)) + local cursor = G.api.nvim_win_get_cursor(0) + local line, col = cursor[1], cursor[2] return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil end From 2ffc088aa272149bf70ca67622c4fad3aff2d747 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 15:53:50 +0800 Subject: [PATCH 11/29] refactor: textwidth=0, simplify G.map/delmap, drop redundant opt, reduce lualine refresh --- lua/G.lua | 16 ++---------- lua/keymap.lua | 61 +++++++++++++++++++++------------------------ lua/options.lua | 2 +- lua/plugs/theme.lua | 6 ++--- 4 files changed, 35 insertions(+), 50 deletions(-) diff --git a/lua/G.lua b/lua/G.lua index 17909a7..0212ddd 100644 --- a/lua/G.lua +++ b/lua/G.lua @@ -15,25 +15,13 @@ G.cgp = vim.nvim_create_augroup function G.map(maps) for _, map in pairs(maps) do - if #map == 3 then - vim.keymap.set(map[1], map[2], map[3], { noremap = true }) - elseif #map == 4 then - vim.keymap.set(map[1], map[2], map[3], map[4]) - else - print("太多变量了") - end + vim.keymap.set(map[1], map[2], map[3], map[4] or { noremap = true }) end end function G.delmap(maps) for _, map in pairs(maps) do - if #map == 2 then - vim.keymap.del(map[1], map[2], {}) - elseif #map == 3 then - vim.keymap.del(map[1], map[2], map[3]) - else - print("太多变量了") - end + vim.keymap.del(map[1], map[2], map[3] or {}) end end diff --git a/lua/keymap.lua b/lua/keymap.lua index b5496b7..72e9dfb 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -1,42 +1,39 @@ -local opt = { noremap = true } - -- base G.map({ - { 'n', 'nh', ':nohlsearch', opt }, - { 'n', 'rp', ':%s/', opt }, + { 'n', 'nh', ':nohlsearch' }, + { 'n', 'rp', ':%s/' }, - { 'v', 'L', '$', opt }, - { 'v', 'H', '^', opt }, - { 'n', 'L', '$', opt }, - { 'n', 'H', '^', opt }, - { 'v', '>', '>gv', opt }, - { 'v', '<', '', '>gv' }, + { 'v', '<', '', '>>', opt }, - { 'n', '<', '<<', opt }, - { 'n', '?', ':set hlsearch?', opt }, - { 'n', '/', ':set hlsearch/', opt }, + { 'n', '>', '>>' }, + { 'n', '<', '<<' }, + { 'n', '?', ':set hlsearch?' }, + { 'n', '/', ':set hlsearch/' }, - { 'n', '', ':tabn', opt }, - { 'n', '', ':tabp', opt }, + { 'n', '', ':tabn' }, + { 'n', '', ':tabp' }, - { 'n', '', 'j', opt }, - { 'n', '', 'h', opt }, - { 'n', '', 'k', opt }, - { 'n', '', 'l', opt }, + { 'n', '', 'j' }, + { 'n', '', 'h' }, + { 'n', '', 'k' }, + { 'n', '', 'l' }, - { 'n', '', ':q', opt }, - { 'n', '', ':w !sudo tee %', opt }, - { 'n', '', ':q!', opt }, - { 'v', '', '"+y', opt }, + { 'n', '', ':q' }, + { 'n', '', ':w !sudo tee %' }, + { 'n', '', ':q!' }, + { 'v', '', '"+y' }, - { 'n', 'y', 'ggyG', opt }, - { 'n', 'p', 'ggpG', opt }, - { 'n', 'v', 'ggVG', opt }, - - { 'n', '', ':res -5', opt }, - { 'n', '', ':res +5', opt }, - { 'n', '', ':vertical resize -5', opt }, - { 'n', '', ':vertical resize +5', opt }, + { 'n', 'y', 'ggyG' }, + { 'n', 'p', 'ggpG' }, + { 'n', 'v', 'ggVG' }, + { 'n', '', ':res -5' }, + { 'n', '', ':res +5' }, + { 'n', '', ':vertical resize -5' }, + { 'n', '', ':vertical resize +5' }, }) diff --git a/lua/options.lua b/lua/options.lua index d053a69..8b7ff08 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -29,7 +29,7 @@ G.opt.ignorecase = true G.opt.incsearch = true -- 不换行 -G.opt.textwidth = 999 +G.opt.textwidth = 0 G.opt.wrap = false diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua index 3e1428f..15db832 100644 --- a/lua/plugs/theme.lua +++ b/lua/plugs/theme.lua @@ -20,9 +20,9 @@ return { always_divide_middle = true, globalstatus = false, refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, + statusline = 2000, + tabline = 2000, + winbar = 2000, } }, sections = { From b01f94be0a7056349ec25d3490e5d7a5e7abe211 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:16:45 +0800 Subject: [PATCH 12/29] docs: add README and key config comments --- README.md | 171 +++++++++++++++++++++++++++++++++++ init.lua | 4 +- lua/G.lua | 2 + lua/lsp/basedpyright.lua | 1 + lua/lsp/go.lua | 1 + lua/options.lua | 5 +- lua/plugs/dev.lua | 2 +- lua/plugs/edit-plugs.lua | 6 +- lua/plugs/mason.lua | 2 +- lua/plugs/nvim-cmp.lua | 8 +- lua/plugs/nvim-lspconfig.lua | 2 + lua/plugs/treesitter.lua | 4 +- 12 files changed, 199 insertions(+), 9 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4dd55c2 --- /dev/null +++ b/README.md @@ -0,0 +1,171 @@ +# Neovim 配置 + +基于 Neovim 0.12+,lazy.nvim 管理插件,支持原生和 VSCode Neovim 双模式。 + +## 目录结构 + +``` +init.lua # 入口:安装 lazy.nvim → keymaps → 分支判断 +lua/ + G.lua # 全局工具单例(vim API 别名 + 映射/命令/自动命令封装) + keymap.lua # 基础快捷键 + options.lua # vim.opt 基础设置 + vsc.lua # VSCode Neovim 模式下的精简启动(仅编辑插件) + plugs.lua # 插件聚合器(10 个模块) + plugs/ + nvim-lspconfig.lua # LSP 核心:7 个 server 注册 + LSP 快捷键 + mason.lua # LSP server 自动安装(Mason) + nvim-cmp.lua # 补全引擎(nvim-cmp + vsnip + lspkind + 命令行补全) + treesitter.lua # 语法高亮 + 自动安装 parser + symbols-outline.lua # 代码大纲侧边栏 + winbar.lua # 顶部文件路径 + 函数标签 + nvimtree.lua # 文件树 + theme.lua # 主题(tokyonight)+ 状态栏(lualine)+ 标签栏(tabline) + edit-plugs.lua # 编辑增强(fzf/surround/wildfire/多光标/对齐/Copilot/折叠/hop) + dev.lua # 开发工具(colorizer/go.nvim/conda/toggleterm) + lsp/ + lua.lua # Lua LSP(LuaJIT + 全局变量声明) + c.lua # C/C++ LSP(clangd)+ :R 编译运行 + bash.lua # Bash LSP + :R 运行 + go.lua # Go LSP(gopls)+ :R / :Rgin 运行 + basedpyright.lua # Python LSP(basedpyright)+ :R 运行 + yaml.lua # YAML LSP + GitHub Workflow schema + json.lua # JSON LSP +snippets/ # 代码片段(C/Go/JSON/Lua) +``` + +## 启动流程 + +``` +G.lua → 克隆/定位 lazy.nvim → keymap.lua → + 若 VSCode 环境 → vsc.lua(仅编辑插件) + 若原生 Neovim → options.lua → lazy.setup(plugs.lua) +``` + +## 插件总表(~28 个) + +| 分类 | 插件 | 用途 | +|------|------|------| +| LSP | nvim-lspconfig | LSP 客户端配置 | +| LSP | Mason + mason-lspconfig | LSP server 自动下载 | +| LSP | lua_ls, clangd, bashls, gopls, basedpyright, yamlls, jsonls | 7 种语言 LSP | +| 补全 | nvim-cmp + cmp-nvim-lsp + cmp-buffer + cmp-path + cmp-cmdline | 补全引擎 | +| 补全 | vim-vsnip + cmp-vsnip | 代码片段引擎 | +| 补全 | lspkind-nvim | 补全图标 | +| 语法 | nvim-treesitter | 语法高亮 + 缩进检测 | +| 语法 | nvim-autopairs | 自动括号配对 | +| 语法 | nvim-hlchunk | 括号层级和缩进色块 | +| 主题 | tokyonight.nvim | 配色方案 | +| UI | lualine.nvim | 状态栏 | +| UI | tabline.nvim | 顶部标签栏 | +| UI | winbar.nvim | 顶部文件名 + 函数路径 | +| UI | nvim-tree.lua | 侧边文件树 | +| UI | symbols-outline.nvim | 代码大纲 | +| UI | colorizer | 颜色值可视化 | +| 编辑 | nvim-fzf | 模糊搜索 | +| 编辑 | vim-surround | 环绕字符操作(cs/ds/ys) | +| 编辑 | wildfire.vim | 选区自动扩大/缩小 | +| 编辑 | vim-multiple-cursors | 多光标编辑 | +| 编辑 | vim-easy-align | 对齐排版 | +| 编辑 | hop.nvim | 快速跳转(替代 f/F/t/T) | +| 编辑 | nvim-ufo | 现代折叠(treesitter 驱动) | +| AI | copilot.vim | GitHub Copilot 行内补全 | +| 语言 | go.nvim | Go 开发增强(test/coverage 等) | +| 语言 | nvim-conda | Conda 环境切换 | +| 终端 | toggleterm.nvim | 浮层终端 | + +## 快捷键速查 + +### 基础操作 + +| 键 | 模式 | 功能 | +|----|------|------| +| `nh` | n | 清除搜索高亮 | +| `rp` | n | 全局替换 `:%s/` | +| `y` / `p` / `v` | n | 全文件复制/粘贴/全选 | +| `` / `` | n | 切换左右标签页 | +| `` | n | 窗口间跳转 | +| `` / `` | n | 关闭窗口 / 强制关闭 | +| `` | n | sudo 强制保存 | +| `` | v | 复制到系统剪切板 | +| `` | n | 文件树开关 | +| `` | n | 代码大纲开关 | +| `` | n/i | 终端开关 | +| `` | n | 调整窗口大小 | + +### LSP + +| 键 | 模式 | 功能 | +|----|------|------| +| `gd` | n | 跳转到定义 | +| `gh` | n | 悬浮文档 | +| `gD` | n | 跳转到声明 | +| `gi` | n | 跳转到实现 | +| `gr` | n | 查找引用 | +| `` | n | 重命名符号 | +| `` | n | 代码格式化 | + +### 语言运行 `:R` + +| 语言 | 命令 | +|------|------| +| C/C++ | 编译 → 运行 → 删二进制 | +| Bash | `sh %` | +| Go | `go run %`;`:Rgin` 运行 `main.go` | +| Python | `python3 %` | + +### 补全(插入模式) + +| 键 | 功能 | +|----|------| +| `` / `` | 选择补全项 / snippet 占位跳转 | +| ``(未选择时) | 换行 | +| ``(选择后) | 确认补全 | +| `Tab` | Copilot 接受建议 | + +### 命令栏 / 搜索栏补全 + +| 键 | 功能 | +|----|------| +| `Tab` / `S-Tab` | 选择补全项 | +| ``(未选择时) | 直接执行命令/搜索 | +| ``(选择后) | 确认补全 | + +### 编辑 + +| 键 | 模式 | 功能 | +|----|------|------| +| `f` / `F` / `t` / `T` | n | hop 行内跳转(覆盖原生) | +| `` | n | hop 双字符跳转 | +| `ga` / `=` | v | EasyAlign 对齐 | +| `gc` / `gcc` | n | 注释切换(Neovim 0.12 内置) | +| `zc` / `zo` / `za` / `zR` | n | 折叠(ufo) | + +### 文件树内 + +| 键 | 功能 | +|----|------| +| `v` | 垂直分屏打开 | +| `s` | 水平分屏打开 | + +## LSP 说明 + +- 使用 Neovim 0.11+ 新 API:`vim.lsp.config` / `vim.lsp.enable` +- `capabilities` 由 `cmp_nvim_lsp` 统一在 `nvim-lspconfig.lua` 注入,各语言文件不重复 require +- `basedpyright` 替代了 `pyright`(类型检查更强) +- Mason 自动安装:bashls、lua_ls、jsonls、yamlls(basedpyright 需手动装) +- Treesitter 关闭了 txt parser,禁用了 Go(恢复中由 go.nvim 处理) + +## 安装 + +```bash +# 克隆到 Neovim 配置目录 +git clone https://git.qyhhh.top/newbie/nvim.git ~/.config/nvim + +# 首次启动会自动安装 lazy.nvim 及全部插件 +nvim +``` + +## 许可 + +MIT diff --git a/init.lua b/init.lua index 96411f5..3504cc5 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,6 @@ G = require('G') --- 安装/定位 lazy.nvim(VSCode 和原生 Neovim 都需要) +-- lazy.nvim 必须在 VSCode 和原生环境都可用:原生用它装插件,VSCode 的 vsc.lua 也需要 require('lazy') local lazypath = G.fn.stdpath('data') .. '/lazy/lazy.nvim' if not G.loop.fs_stat(lazypath) then G.fn.system({ @@ -14,9 +14,11 @@ if not G.loop.fs_stat(lazypath) then end G.opt.rtp:prepend(lazypath) +-- keymap 在两个环境都加载(基础键位都不依赖插件) require('keymap') if G.g.vscode then + -- VSCode Neovim 模式:只加载编辑插件,不加载 LSP/补全/主题/选项 require('vscode') else require('options') diff --git a/lua/G.lua b/lua/G.lua index 0212ddd..70eaf76 100644 --- a/lua/G.lua +++ b/lua/G.lua @@ -13,6 +13,7 @@ G.lb = vim.lsp.buf G.dic = vim.diagnostic G.cgp = vim.nvim_create_augroup +-- 批量设置键映射,3 元素自动加 { noremap = true },4 元素用传入的 opts function G.map(maps) for _, map in pairs(maps) do vim.keymap.set(map[1], map[2], map[3], map[4] or { noremap = true }) @@ -41,6 +42,7 @@ function G.au(even, opts) return G.api.nvim_create_autocmd(even, opts) end +-- :R 命令工厂:在下方分屏开终端运行指定命令,省去 5 个 LSP 文件的重复代码 function G.run_cmd(cmd) return function() G.cmd [[set splitbelow | sp]] diff --git a/lua/lsp/basedpyright.lua b/lua/lsp/basedpyright.lua index 873421c..fa32aee 100644 --- a/lua/lsp/basedpyright.lua +++ b/lua/lsp/basedpyright.lua @@ -1,4 +1,5 @@ return { + -- basedpyright:pyright 的增强分支,类型检查更强。capabilities 由 nvim-lspconfig.lua 统一注入 settings = { basedpyright = { analysis = { diff --git a/lua/lsp/go.lua b/lua/lsp/go.lua index e5d19ca..52a9b61 100644 --- a/lua/lsp/go.lua +++ b/lua/lsp/go.lua @@ -1,4 +1,5 @@ return { + -- gopls + :R(go run %)+ :Rgin(go run ./main.go,主入口专用) on_attach = function() G.api.nvim_create_user_command('R', G.run_cmd('go run %'), {}) G.api.nvim_create_user_command('Rgin', G.run_cmd('go run ./main.go'), {}) diff --git a/lua/options.lua b/lua/options.lua index 8b7ff08..d6bafc5 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -36,10 +36,11 @@ G.opt.wrap = false -- 文件判断 G.cmd("filetype plugin indent on") --- 取消换行注释 +-- 取消换行注释:o 和 O 不自动续注释;回车继续续注释(一次设定,formatoptions 不会变) G.opt.formatoptions = G.opt.formatoptions - "o" + "r" +-- 进入插入模式时自动关搜索高亮(个人偏好:打字时不想被高亮干扰) G.au({ "InsertEnter" }, { pattern = { "*" }, callback = function() @@ -47,6 +48,7 @@ G.au({ "InsertEnter" }, { end, }) +-- .code-snippets 文件强制识别为 JSON(方便编辑,否则无法语法高亮) G.au({ "VimEnter", "BufEnter" }, { pattern = { "*.code-snippets" }, callback = function() @@ -55,6 +57,7 @@ G.au({ "VimEnter", "BufEnter" }, { }) +-- 自动检测 Conda Python 环境,优先用 conda 里的 python local function isempty(s) return s == nil or s == "" end diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua index 6d6fe05..1ee3e5b 100644 --- a/lua/plugs/dev.lua +++ b/lua/plugs/dev.lua @@ -9,7 +9,7 @@ return { -- end -- }, { - -- go开发 + -- go 开发:只对 go/gomod 文件加载,build 时检测是否装了 Go(无 Go 环境静默跳过) "ray-x/go.nvim", dependencies = { "ray-x/guihua.lua", diff --git a/lua/plugs/edit-plugs.lua b/lua/plugs/edit-plugs.lua index a209b64..b8a3026 100644 --- a/lua/plugs/edit-plugs.lua +++ b/lua/plugs/edit-plugs.lua @@ -23,11 +23,12 @@ return { }) end }, - -- 注释插件(neovim 0.12 内置 gc,用 treesitter,先注释测试) + -- 注释插件:Neovim 0.12 内置 treesitter gc/gcc 注释切换,暂注释掉此插件测试 -- { -- 'tpope/vim-commentary', -- }, { + -- Copilot 懒加载:只在插入模式需要(和 nvim-cmp 共用 Tab 键,cmp 改用 C-n/C-p 避让) 'github/copilot.vim', -- github copilot event = "InsertEnter", }, @@ -58,7 +59,8 @@ return { end }, { - -- hop + -- hop 快速跳转:用 f/F/t/T 做行内单字符跳转, 做双字符跳转 + -- 注意:这会覆盖 Vim 原生的 f/F/t/T "phaazon/hop.nvim", branch = "v2", keys = { diff --git a/lua/plugs/mason.lua b/lua/plugs/mason.lua index 019c3e1..831b658 100644 --- a/lua/plugs/mason.lua +++ b/lua/plugs/mason.lua @@ -18,7 +18,7 @@ return { require("mason-lspconfig").setup({ ensure_installed = { "bashls", - -- "basedpyright", + -- "basedpyright", -- Python LSP 需手动装(有的机器不用 Python) "lua_ls", "jsonls", "yamlls", diff --git a/lua/plugs/nvim-cmp.lua b/lua/plugs/nvim-cmp.lua index 191a2e9..60bd2a4 100644 --- a/lua/plugs/nvim-cmp.lua +++ b/lua/plugs/nvim-cmp.lua @@ -33,6 +33,7 @@ return { vim.fn["vsnip#anonymous"](args.body) end, }, + -- 补全来源优先级:LSP > 片段 > buffer > 路径 sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'vsnip' }, @@ -40,8 +41,10 @@ return { { name = 'buffer' }, { name = 'path' } ), + -- 插入模式映射:C-n/C-p 选择,CR 未选时换行(避免冲突 Copilot 的 Tab) mapping = cmp.mapping.preset.insert({ + -- 回车:手动选择后确认,未选时 fallback 到换行 [""] = cmp.mapping({ i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }), c = function(fallback) @@ -53,6 +56,7 @@ return { end, }), + -- C-n:选下一个补全项 / 展开 vsnip 占位 / 手动触发补全 [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() @@ -103,7 +107,7 @@ return { } require('cmp').setup(cmp_opt) - -- 命令栏补全(Tab 导航,回车无选择时直接执行) + -- 命令栏补全:Tab 导航,回车时若有手动选择则确认,否则直接执行命令(不卡住) require('cmp').setup.cmdline(':', { mapping = { [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'c' }), @@ -113,7 +117,7 @@ return { if cmp.visible() and cmp.get_active_entry() then cmp.confirm({ select = false }) else - fallback() + fallback() -- 没选的时候 fallback = 直接执行命令 end end, }), diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua index ddfb22d..f19e1cb 100644 --- a/lua/plugs/nvim-lspconfig.lua +++ b/lua/plugs/nvim-lspconfig.lua @@ -19,6 +19,8 @@ return { jsonls = require('lsp.json'), } + -- capabilities 在此处统一注入,各 lsp/*.lua 不单独 require cmp_nvim_lsp + -- 避免模块层面 require 带来的隐式依赖 local capabilities = require('cmp_nvim_lsp').default_capabilities() for server, config in pairs(servers) do config.capabilities = capabilities diff --git a/lua/plugs/treesitter.lua b/lua/plugs/treesitter.lua index 4da2bfd..d4a0f56 100644 --- a/lua/plugs/treesitter.lua +++ b/lua/plugs/treesitter.lua @@ -1,6 +1,6 @@ return { { - -- 语法高亮 -- + -- 语法高亮:auto_install=true 自动装 parser,ignore_install 跳过 txt 'nvim-treesitter/nvim-treesitter', config = function() local treesitter_opt = { @@ -12,6 +12,7 @@ return { auto_install = true, highlight = { enable = true, + -- 大于 100KB 的文件关闭 treesitter 高亮(性能优化) disable = function(_, buf) local max_filesize = 100 * 1024 -- 100 KB local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) @@ -21,6 +22,7 @@ return { end, additional_vim_regex_highlighting = false, }, + -- 自定义 Vue parser:上游 tree-sitter-html 不识别 .vue 单文件组件 parsers = { vue = { install_info = { From 480cfff6570009b5525741bbba93e101d2727f27 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:38:27 +0800 Subject: [PATCH 13/29] feat: add Reasonix keymap with adaptive split direction --- lua/keymap.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/keymap.lua b/lua/keymap.lua index 72e9dfb..aa0d4ba 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -36,4 +36,15 @@ G.map({ { 'n', '', ':res +5' }, { 'n', '', ':vertical resize -5' }, { 'n', '', ':vertical resize +5' }, + + -- Reasonix AI agent:根据窗口宽高自适应方向(宽→上下分屏,高→左右分屏) + { 'n', '', function() + local ui = vim.api.nvim_list_uis()[1] + local wide = ui.width > ui.height + local term = require('toggleterm.terminal').Terminal:new({ + direction = wide and 'horizontal' or 'vertical', + cmd = 'reasonix', + }) + term:toggle() + end, { noremap = true } }, }) From 3c5fa11ef1f77fd8a4470823f4d390d3b996435f Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:38:43 +0800 Subject: [PATCH 14/29] docs: add Reasonix keymap to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4dd55c2..ee9f5ff 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ G.lua → 克隆/定位 lazy.nvim → keymap.lua → | `` | n | 文件树开关 | | `` | n | 代码大纲开关 | | `` | n/i | 终端开关 | +| `` | n | Reasonix AI:自适应分屏(横屏→下方,竖屏→右侧) | | `` | n | 调整窗口大小 | ### LSP From 3253a2b20f681d087c38d35af198d4d8ad8e3cb7 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:39:38 +0800 Subject: [PATCH 15/29] feat: adaptive split same as Reasonix, works in both n/i modes --- lua/keymap.lua | 19 +++++++++++++------ lua/plugs/dev.lua | 11 ++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lua/keymap.lua b/lua/keymap.lua index aa0d4ba..3c2ed23 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -36,15 +36,22 @@ G.map({ { 'n', '', ':res +5' }, { 'n', '', ':vertical resize -5' }, { 'n', '', ':vertical resize +5' }, +}) - -- Reasonix AI agent:根据窗口宽高自适应方向(宽→上下分屏,高→左右分屏) - { 'n', '', function() - local ui = vim.api.nvim_list_uis()[1] +-- 终端 / Reasonix:根据窗口宽高自适应分屏方向(横屏→下方,竖屏→右侧) +do + local function split_term(ui, cmd) local wide = ui.width > ui.height local term = require('toggleterm.terminal').Terminal:new({ direction = wide and 'horizontal' or 'vertical', - cmd = 'reasonix', + cmd = cmd, }) term:toggle() - end, { noremap = true } }, -}) + end + + G.map({ + { 'n', '', function() split_term(vim.api.nvim_list_uis()[1]) end, { noremap = true } }, + { 'i', '', function() split_term(vim.api.nvim_list_uis()[1]) end, { noremap = true } }, + { 'n', '', function() split_term(vim.api.nvim_list_uis()[1], 'reasonix') end, { noremap = true } }, + }) +end diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua index 1ee3e5b..b906bcc 100644 --- a/lua/plugs/dev.lua +++ b/lua/plugs/dev.lua @@ -32,22 +32,19 @@ return { dependencies = { "nvim-lua/plenary.nvim" }, }, { - -- 终端 + -- 终端(方向由 keymap.lua 自适应控制) 'akinsho/toggleterm.nvim', version = "*", config = function() require("toggleterm").setup { - -- size can be a number or function which is passed the current terminal size = 10, - open_mapping = [[]], - hide_numbers = true, -- hide the number column in toggleterm buffers + hide_numbers = true, shade_filetypes = {}, shade_terminals = true, - shading_factor = 1, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + shading_factor = 1, start_in_insert = true, - insert_mappings = true, -- whether or not the open mapping applies in insert mode persist_size = true, - direction = 'horizontal', + -- direction 不写死,由 keymap 创建时动态决定 } end } From dcfef43b07aa25bb036338f3f494d5fb799365d8 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:40:19 +0800 Subject: [PATCH 16/29] refactor: Reasonix terminal size matches nvimtree (30cols vertical, 10rows horizontal) --- lua/keymap.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/keymap.lua b/lua/keymap.lua index 3c2ed23..9fb0071 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -45,6 +45,8 @@ do local term = require('toggleterm.terminal').Terminal:new({ direction = wide and 'horizontal' or 'vertical', cmd = cmd, + -- 横屏→高度 10 行;竖屏→宽度 ≈ nvimtree(30 列) + size = wide and 10 or math.floor(ui.width * 0.3), }) term:toggle() end From 8334f6042a965247604dc80eb184f9b0f2bf89d6 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:46:36 +0800 Subject: [PATCH 17/29] =?UTF-8?q?fix:=20swap=20terminal=20split=20directio?= =?UTF-8?q?n=20=E2=80=94=20wide=E2=86=92right,=20tall=E2=86=92bottom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/keymap.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/keymap.lua b/lua/keymap.lua index 9fb0071..0cfca1a 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -38,15 +38,15 @@ G.map({ { 'n', '', ':vertical resize +5' }, }) --- 终端 / Reasonix:根据窗口宽高自适应分屏方向(横屏→下方,竖屏→右侧) +-- 终端 / Reasonix:横屏→右侧,竖屏→下方 do local function split_term(ui, cmd) - local wide = ui.width > ui.height + local tall = ui.height > ui.width local term = require('toggleterm.terminal').Terminal:new({ - direction = wide and 'horizontal' or 'vertical', + -- 横屏→右侧(垂直分屏);竖屏→下方(水平分屏) + direction = tall and 'horizontal' or 'vertical', cmd = cmd, - -- 横屏→高度 10 行;竖屏→宽度 ≈ nvimtree(30 列) - size = wide and 10 or math.floor(ui.width * 0.3), + size = tall and 10 or math.floor(ui.width * 0.3), }) term:toggle() end From bb1a4df9fad7ce9bf555d9fffd847f03b1d1ada0 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:49:10 +0800 Subject: [PATCH 18/29] =?UTF-8?q?fix:=20terminal=20size=2030%=20=E2=86=92?= =?UTF-8?q?=2040=20cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/keymap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/keymap.lua b/lua/keymap.lua index 0cfca1a..201c811 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -46,7 +46,7 @@ do -- 横屏→右侧(垂直分屏);竖屏→下方(水平分屏) direction = tall and 'horizontal' or 'vertical', cmd = cmd, - size = tall and 10 or math.floor(ui.width * 0.3), + size = tall and 10 or 40, }) term:toggle() end From e45a3b991e45524f9f11e6ece1b9cb5c2a62d5b4 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 16:53:09 +0800 Subject: [PATCH 19/29] feat: terminal persistence (toggle show/hide), size 40%-45% like IDE split --- lua/keymap.lua | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lua/keymap.lua b/lua/keymap.lua index 201c811..a316c09 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -38,22 +38,27 @@ G.map({ { 'n', '', ':vertical resize +5' }, }) --- 终端 / Reasonix:横屏→右侧,竖屏→下方 +-- 终端 / Reasonix:横屏→右侧(45%屏宽),竖屏→下方(40%屏高),持久化 buffer(按 c-t/c-i 切换显隐) do - local function split_term(ui, cmd) + local terms = {} -- 缓存,复用同一个终端实例 + + local function split_term(cmd) + local ui = vim.api.nvim_list_uis()[1] local tall = ui.height > ui.width - local term = require('toggleterm.terminal').Terminal:new({ - -- 横屏→右侧(垂直分屏);竖屏→下方(水平分屏) - direction = tall and 'horizontal' or 'vertical', - cmd = cmd, - size = tall and 10 or 40, - }) - term:toggle() + local name = cmd or '__shell__' + if not terms[name] or not terms[name]:is_open() then + terms[name] = require('toggleterm.terminal').Terminal:new({ + direction = tall and 'horizontal' or 'vertical', + cmd = cmd, + size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45), + }) + end + terms[name]:toggle() end G.map({ - { 'n', '', function() split_term(vim.api.nvim_list_uis()[1]) end, { noremap = true } }, - { 'i', '', function() split_term(vim.api.nvim_list_uis()[1]) end, { noremap = true } }, - { 'n', '', function() split_term(vim.api.nvim_list_uis()[1], 'reasonix') end, { noremap = true } }, + { 'n', '', function() split_term() end, { noremap = true } }, + { 'i', '', function() split_term() end, { noremap = true } }, + { 'n', '', function() split_term('reasonix') end, { noremap = true } }, }) end From 131bcb8bf54f3cad6cc2b521f328e35b34f891cb Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 17:00:29 +0800 Subject: [PATCH 20/29] refactor: extract terminal logic into addons/term --- lua/addons/term.lua | 37 +++++++++++++++++++++++++++++++++++++ lua/keymap.lua | 31 +++++++------------------------ 2 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 lua/addons/term.lua diff --git a/lua/addons/term.lua b/lua/addons/term.lua new file mode 100644 index 0000000..42b5610 --- /dev/null +++ b/lua/addons/term.lua @@ -0,0 +1,37 @@ +-- addons/term.lua — 持久化自适应终端 +-- +-- 用法: +-- local T = require('addons.term') +-- T.shell() -- 打开/关闭普通终端() +-- T.open('reasonix') -- 打开/关闭 Reasonix() +-- +-- 特性: +-- - 同一个终端实例持久化(关掉再开回来,对话不丢) +-- - 窗口方向自适应:横屏→右侧(45%),竖屏→下方(40%) +-- - 依赖 toggleterm.nvim + +local M = {} + +local terms = {} -- 缓存终端实例,key 是命令名(nil = 普通 shell) + +function M.open(cmd) + local ui = vim.api.nvim_list_uis()[1] + local tall = ui.height > ui.width + local name = cmd or '__shell__' + + if not terms[name] or not terms[name]:is_open() then + terms[name] = require('toggleterm.terminal').Terminal:new({ + direction = tall and 'horizontal' or 'vertical', + cmd = cmd, + size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45), + }) + end + + terms[name]:toggle() +end + +function M.shell() + M.open(nil) +end + +return M diff --git a/lua/keymap.lua b/lua/keymap.lua index a316c09..35010cf 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -38,27 +38,10 @@ G.map({ { 'n', '', ':vertical resize +5' }, }) --- 终端 / Reasonix:横屏→右侧(45%屏宽),竖屏→下方(40%屏高),持久化 buffer(按 c-t/c-i 切换显隐) -do - local terms = {} -- 缓存,复用同一个终端实例 - - local function split_term(cmd) - local ui = vim.api.nvim_list_uis()[1] - local tall = ui.height > ui.width - local name = cmd or '__shell__' - if not terms[name] or not terms[name]:is_open() then - terms[name] = require('toggleterm.terminal').Terminal:new({ - direction = tall and 'horizontal' or 'vertical', - cmd = cmd, - size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45), - }) - end - terms[name]:toggle() - end - - G.map({ - { 'n', '', function() split_term() end, { noremap = true } }, - { 'i', '', function() split_term() end, { noremap = true } }, - { 'n', '', function() split_term('reasonix') end, { noremap = true } }, - }) -end +-- 终端 / Reasonix(addons/term:持久化 + 自适应分屏) +local T = require('addons.term') +G.map({ + { 'n', '', T.shell, { noremap = true } }, + { 'i', '', T.shell, { noremap = true } }, + { 'n', '', function() T.open('reasonix') end, { noremap = true } }, +}) From 0727f447d804cc38d381a2d5eddc296081fe5e33 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 17:01:09 +0800 Subject: [PATCH 21/29] feat: add lazygit shortcut (gg) via addons/term --- lua/keymap.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/keymap.lua b/lua/keymap.lua index 35010cf..a1e5fb3 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -38,10 +38,11 @@ G.map({ { 'n', '', ':vertical resize +5' }, }) --- 终端 / Reasonix(addons/term:持久化 + 自适应分屏) +-- 终端(addons/term:持久化 + 自适应分屏) local T = require('addons.term') G.map({ - { 'n', '', T.shell, { noremap = true } }, - { 'i', '', T.shell, { noremap = true } }, - { 'n', '', function() T.open('reasonix') end, { noremap = true } }, + { 'n', '', T.shell, { noremap = true } }, + { 'i', '', T.shell, { noremap = true } }, + { 'n', '', function() T.open('reasonix') end, { noremap = true } }, + { 'n', 'gg', function() T.open('lazygit') end, { noremap = true } }, }) From fd2e7263f75dd83b2556efbb9679a296014fd7cf Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 19:14:24 +0800 Subject: [PATCH 22/29] =?UTF-8?q?rename:=20term=20=E2=86=92=20QQdock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/addons/{term.lua => QQdock.lua} | 0 lua/keymap.lua | 2 +- term-plugin | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) rename lua/addons/{term.lua => QQdock.lua} (100%) create mode 160000 term-plugin diff --git a/lua/addons/term.lua b/lua/addons/QQdock.lua similarity index 100% rename from lua/addons/term.lua rename to lua/addons/QQdock.lua diff --git a/lua/keymap.lua b/lua/keymap.lua index a1e5fb3..eec9d21 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -39,7 +39,7 @@ G.map({ }) -- 终端(addons/term:持久化 + 自适应分屏) -local T = require('addons.term') +local T = require('addons.QQdock') G.map({ { 'n', '', T.shell, { noremap = true } }, { 'i', '', T.shell, { noremap = true } }, diff --git a/term-plugin b/term-plugin new file mode 160000 index 0000000..9e8f286 --- /dev/null +++ b/term-plugin @@ -0,0 +1 @@ +Subproject commit 9e8f286a62c95f0b9e9dd4fcea207be536ed7f3e From 9ae6fcb2ad48084296fa1e59cfd7e082fe33af16 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 19:14:30 +0800 Subject: [PATCH 23/29] chore: remove embedded term-plugin repo --- term-plugin | 1 - 1 file changed, 1 deletion(-) delete mode 160000 term-plugin diff --git a/term-plugin b/term-plugin deleted file mode 160000 index 9e8f286..0000000 --- a/term-plugin +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9e8f286a62c95f0b9e9dd4fcea207be536ed7f3e From 7884551a2611aef259d77d4c74946702f3e17b4b Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 19:18:35 +0800 Subject: [PATCH 24/29] restore: local addons/QQdock pending RO fs fix, remote repo at git.qyhhh.top/newbie/QQdock.nvim --- lua/addons/QQdock.lua | 20 ++++++++++---------- lua/keymap.lua | 12 ++++++------ lua/plugs/dev.lua | 3 +-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lua/addons/QQdock.lua b/lua/addons/QQdock.lua index 42b5610..9510918 100644 --- a/lua/addons/QQdock.lua +++ b/lua/addons/QQdock.lua @@ -1,21 +1,21 @@ --- addons/term.lua — 持久化自适应终端 +-- addons/QQdock.lua — 持久化自适应终端 +-- +-- 注意:这是 QQdock.nvim 插件的本地副本(根分区只读,无法通过 lazy 装远程插件) +-- 远程仓库:https://git.qyhhh.top/newbie/QQdock.nvim -- -- 用法: --- local T = require('addons.term') --- T.shell() -- 打开/关闭普通终端() --- T.open('reasonix') -- 打开/关闭 Reasonix() --- --- 特性: --- - 同一个终端实例持久化(关掉再开回来,对话不丢) --- - 窗口方向自适应:横屏→右侧(45%),竖屏→下方(40%) --- - 依赖 toggleterm.nvim +-- local Q = require('addons.QQdock') +-- Q.shell() -- 普通终端 +-- Q.open('reasonix') -- Reasonix +-- Q.open('lazygit') -- gg lazygit local M = {} -local terms = {} -- 缓存终端实例,key 是命令名(nil = 普通 shell) +local terms = {} function M.open(cmd) local ui = vim.api.nvim_list_uis()[1] + if not ui then return end local tall = ui.height > ui.width local name = cmd or '__shell__' diff --git a/lua/keymap.lua b/lua/keymap.lua index eec9d21..c641cd9 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -38,11 +38,11 @@ G.map({ { 'n', '', ':vertical resize +5' }, }) --- 终端(addons/term:持久化 + 自适应分屏) -local T = require('addons.QQdock') +-- 终端 / Reasonix / lazygit(addons/QQdock:持久化 + 自适应分屏) +local Q = require('addons.QQdock') G.map({ - { 'n', '', T.shell, { noremap = true } }, - { 'i', '', T.shell, { noremap = true } }, - { 'n', '', function() T.open('reasonix') end, { noremap = true } }, - { 'n', 'gg', function() T.open('lazygit') end, { noremap = true } }, + { 'n', '', Q.shell, { noremap = true } }, + { 'i', '', Q.shell, { noremap = true } }, + { 'n', '', function() Q.open('reasonix') end, { noremap = true } }, + { 'n', 'gg', function() Q.open('lazygit') end, { noremap = true } }, }) diff --git a/lua/plugs/dev.lua b/lua/plugs/dev.lua index b906bcc..f5e3b6c 100644 --- a/lua/plugs/dev.lua +++ b/lua/plugs/dev.lua @@ -32,7 +32,7 @@ return { dependencies = { "nvim-lua/plenary.nvim" }, }, { - -- 终端(方向由 keymap.lua 自适应控制) + -- toggleterm:被 addons/QQdock 使用的底层终端 'akinsho/toggleterm.nvim', version = "*", config = function() @@ -44,7 +44,6 @@ return { shading_factor = 1, start_in_insert = true, persist_size = true, - -- direction 不写死,由 keymap 创建时动态决定 } end } From a615ae1bb7af9b8a7195fdb02ce39538cf7685ba Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 19:31:07 +0800 Subject: [PATCH 25/29] refactor: QQdock as proper plugin module (lua/QQdock/init.lua) --- lua/{addons/QQdock.lua => QQdock/init.lua} | 0 lua/keymap.lua | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) rename lua/{addons/QQdock.lua => QQdock/init.lua} (100%) diff --git a/lua/addons/QQdock.lua b/lua/QQdock/init.lua similarity index 100% rename from lua/addons/QQdock.lua rename to lua/QQdock/init.lua diff --git a/lua/keymap.lua b/lua/keymap.lua index c641cd9..c3ed04b 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -38,8 +38,9 @@ G.map({ { 'n', '', ':vertical resize +5' }, }) --- 终端 / Reasonix / lazygit(addons/QQdock:持久化 + 自适应分屏) -local Q = require('addons.QQdock') +-- 终端 / Reasonix / lazygit(QQdock.nvim:持久化 + 自适应分屏) +-- TODO: 根分区恢复读写后改为 lazy spec 引用 git.qyhhh.top/newbie/QQdock.nvim,删本地 lua/QQdock/ +local Q = require('QQdock') G.map({ { 'n', '', Q.shell, { noremap = true } }, { 'i', '', Q.shell, { noremap = true } }, From e1009aea83f068ee7fd3c1f562e0d4a7c72963f3 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 19:32:33 +0800 Subject: [PATCH 26/29] refactor: add plugs/QQdock.lua spec (disabled), keep local lua/QQdock/ for now --- lua/plugs.lua | 3 +++ lua/plugs/QQdock.lua | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 lua/plugs/QQdock.lua diff --git a/lua/plugs.lua b/lua/plugs.lua index b0b2319..8fed9e8 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -9,4 +9,7 @@ return { require('plugs.theme'), require('plugs.edit-plugs'), require('plugs.dev'), + -- TODO: 根分区恢复读写后启用 ↓ + -- require('plugs.QQdock'), + -- 同时删 lua/QQdock/ 目录、删 keymap.lua 中的 QQdock 映射段 } diff --git a/lua/plugs/QQdock.lua b/lua/plugs/QQdock.lua new file mode 100644 index 0000000..d2cb975 --- /dev/null +++ b/lua/plugs/QQdock.lua @@ -0,0 +1,25 @@ +-- QQdock.nvim — 持久化自适应终端 +-- 远程仓库:https://git.qyhhh.top/newbie/QQdock.nvim +-- 本地临时副本:lua/QQdock/init.lua(根分区只读期间使用) +-- +-- 恢复读写后操作: +-- 1. 删掉 lua/QQdock/ +-- 2. plugs.lua 追加 require('plugs.QQdock') +-- 3. keymap.lua 不用改(require('QQdock') 自动找到 lazy 安装的版本) + +return { + { + 'newbie/QQdock.nvim', + url = 'https://git.qyhhh.top/newbie/QQdock.nvim.git', + dependencies = { 'akinsho/toggleterm.nvim' }, + config = function() + local Q = require('QQdock') + G.map({ + { 'n', '', Q.shell, { noremap = true } }, + { 'i', '', Q.shell, { noremap = true } }, + { 'n', '', function() Q.open('reasonix') end, { noremap = true } }, + { 'n', 'gg', function() Q.open('lazygit') end, { noremap = true } }, + }) + end, + }, +} From 93650204df1fca1da9028c2a1fe6568481256a9c Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 19:52:07 +0800 Subject: [PATCH 27/29] switch QQdock from local module to lazy spec --- lua/QQdock/init.lua | 37 ------------------------------------- lua/keymap.lua | 9 --------- lua/plugs.lua | 4 +--- 3 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 lua/QQdock/init.lua diff --git a/lua/QQdock/init.lua b/lua/QQdock/init.lua deleted file mode 100644 index 9510918..0000000 --- a/lua/QQdock/init.lua +++ /dev/null @@ -1,37 +0,0 @@ --- addons/QQdock.lua — 持久化自适应终端 --- --- 注意:这是 QQdock.nvim 插件的本地副本(根分区只读,无法通过 lazy 装远程插件) --- 远程仓库:https://git.qyhhh.top/newbie/QQdock.nvim --- --- 用法: --- local Q = require('addons.QQdock') --- Q.shell() -- 普通终端 --- Q.open('reasonix') -- Reasonix --- Q.open('lazygit') -- gg lazygit - -local M = {} - -local terms = {} - -function M.open(cmd) - local ui = vim.api.nvim_list_uis()[1] - if not ui then return end - local tall = ui.height > ui.width - local name = cmd or '__shell__' - - if not terms[name] or not terms[name]:is_open() then - terms[name] = require('toggleterm.terminal').Terminal:new({ - direction = tall and 'horizontal' or 'vertical', - cmd = cmd, - size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45), - }) - end - - terms[name]:toggle() -end - -function M.shell() - M.open(nil) -end - -return M diff --git a/lua/keymap.lua b/lua/keymap.lua index c3ed04b..8f30f02 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -38,12 +38,3 @@ G.map({ { 'n', '', ':vertical resize +5' }, }) --- 终端 / Reasonix / lazygit(QQdock.nvim:持久化 + 自适应分屏) --- TODO: 根分区恢复读写后改为 lazy spec 引用 git.qyhhh.top/newbie/QQdock.nvim,删本地 lua/QQdock/ -local Q = require('QQdock') -G.map({ - { 'n', '', Q.shell, { noremap = true } }, - { 'i', '', Q.shell, { noremap = true } }, - { 'n', '', function() Q.open('reasonix') end, { noremap = true } }, - { 'n', 'gg', function() Q.open('lazygit') end, { noremap = true } }, -}) diff --git a/lua/plugs.lua b/lua/plugs.lua index 8fed9e8..8665e53 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -9,7 +9,5 @@ return { require('plugs.theme'), require('plugs.edit-plugs'), require('plugs.dev'), - -- TODO: 根分区恢复读写后启用 ↓ - -- require('plugs.QQdock'), - -- 同时删 lua/QQdock/ 目录、删 keymap.lua 中的 QQdock 映射段 + require('plugs.QQdock'), } From a210f5e43fc8f4afafa86592e6a79899d99a2a88 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 20:00:10 +0800 Subject: [PATCH 28/29] config: QQdock size horizontal=10 vertical=40 --- lua/plugs/QQdock.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/plugs/QQdock.lua b/lua/plugs/QQdock.lua index d2cb975..99d6dc5 100644 --- a/lua/plugs/QQdock.lua +++ b/lua/plugs/QQdock.lua @@ -13,6 +13,12 @@ return { url = 'https://git.qyhhh.top/newbie/QQdock.nvim.git', dependencies = { 'akinsho/toggleterm.nvim' }, config = function() + require('QQdock').setup({ + size = { + horizontal = 10, -- 竖屏下方终端高度 + vertical = 40, -- 横屏右侧终端宽度 + }, + }) local Q = require('QQdock') G.map({ { 'n', '', Q.shell, { noremap = true } }, From ba27352d7b0187b0b7067abba0d8c9f4d799a61a Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Thu, 11 Jun 2026 20:03:14 +0800 Subject: [PATCH 29/29] fix: pcall QQdock.setup for backward compat with old clone --- lua/plugs/QQdock.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/plugs/QQdock.lua b/lua/plugs/QQdock.lua index 99d6dc5..e750c80 100644 --- a/lua/plugs/QQdock.lua +++ b/lua/plugs/QQdock.lua @@ -13,13 +13,13 @@ return { url = 'https://git.qyhhh.top/newbie/QQdock.nvim.git', dependencies = { 'akinsho/toggleterm.nvim' }, config = function() - require('QQdock').setup({ + local Q = require('QQdock') + pcall(Q.setup, Q, { size = { - horizontal = 10, -- 竖屏下方终端高度 - vertical = 40, -- 横屏右侧终端宽度 + horizontal = 10, + vertical = 40, }, }) - local Q = require('QQdock') G.map({ { 'n', '', Q.shell, { noremap = true } }, { 'i', '', Q.shell, { noremap = true } },