From 94274b126a9eeede0895d429eec488d4a35e9427 Mon Sep 17 00:00:00 2001 From: newbieQQ Date: Wed, 10 Jun 2026 21:59:29 +0800 Subject: [PATCH] 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 })