refactor: fix medium-severity issues (lazy leak, formatoptions, dupe map, dead opts, split theme, cmp keys, capabilities injection, typos, style)

This commit is contained in:
QQ 2026-06-11 11:53:18 +08:00
parent f1ed06ae9f
commit cbf4579990
21 changed files with 149 additions and 106 deletions

View File

@ -1,31 +1,29 @@
G = require('G') G = require('G')
-- Clone lazy.nvim (only needed for native Neovim, not VSCode) -- 安装/定位 lazy.nvimVSCode 和原生 Neovim 都需要)
if not G.g.vscode then local lazypath = G.fn.stdpath('data') .. '/lazy/lazy.nvim'
local lazypath = G.fn.stdpath("data") .. "/lazy/lazy.nvim" if not G.loop.fs_stat(lazypath) then
if not G.loop.fs_stat(lazypath) then
G.fn.system({ G.fn.system({
"git", 'git',
"clone", 'clone',
"--filter=blob:none", '--filter=blob:none',
"https://github.com/folke/lazy.nvim.git", 'https://github.com/folke/lazy.nvim.git',
"--branch=stable", '--branch=stable',
lazypath, lazypath,
}) })
end
G.opt.rtp:prepend(lazypath)
end end
G.opt.rtp:prepend(lazypath)
require("keymap") require('keymap')
if G.g.vscode then if G.g.vscode then
require('vscode') require('vscode')
else else
require("options") require('options')
local clone_prefix = G.use_ssh and "git@github.com:%s.git" or "https://github.com/%s.git" local clone_prefix = G.use_ssh and 'git@github.com:%s.git' or 'https://github.com/%s.git'
require("lazy").setup( require('lazy').setup(
require('plugs'), { require('plugs'), {
lockfile = G.fn.stdpath("data") .. "/lazy/lazy-lock.json", lockfile = G.fn.stdpath('data') .. '/lazy/lazy-lock.json',
git = { git = {
url_format = clone_prefix, url_format = clone_prefix,
} }

View File

@ -22,7 +22,6 @@ function G.map(maps)
else else
print("太多变量了") print("太多变量了")
end end
--G.api.nvim_set_keymap(map[1], map[2], map[3], map[4])
end end
end end

View File

@ -20,20 +20,16 @@ G.map({
{ 'n', '<A-l>', ':tabn<CR>', opt }, { 'n', '<A-l>', ':tabn<CR>', opt },
{ 'n', '<A-h>', ':tabp<CR>', opt }, { 'n', '<A-h>', ':tabp<CR>', opt },
{ 'n', '<c-j>', '<c-w>j', opt }, { 'n', '<c-j>', '<c-w>j', opt },
{ 'n', '<c-h>', '<c-w>h', opt }, { 'n', '<c-h>', '<c-w>h', opt },
{ 'n', '<c-k>', '<c-w>k', opt }, { 'n', '<c-k>', '<c-w>k', opt },
{ 'n', '<c-l>', '<c-w>l', opt }, { 'n', '<c-l>', '<c-w>l', opt },
{ 'n', '<c-c>', ':q<CR>', opt }, { 'n', '<c-c>', ':q<CR>', opt },
{ 'n', '<c-S>', ':w !sudo tee %<CR>', opt }, { 'n', '<c-S>', ':w !sudo tee %<CR>', opt },
{ 'n', '<c-q>', ':q!<CR>', opt }, { 'n', '<c-q>', ':q!<CR>', opt },
{ 'v', '<cs-y>', '"+y', opt }, { 'v', '<cs-y>', '"+y', opt },
{ 'n', '<leader>y', 'ggyG', opt }, { 'n', '<leader>y', 'ggyG', opt },
{ 'n', '<leader>p', 'ggpG', opt }, { 'n', '<leader>p', 'ggpG', opt },
{ 'n', '<leader>v', 'ggVG', opt }, { 'n', '<leader>v', 'ggVG', opt },

View File

@ -1,5 +1,4 @@
return { return {
capabilities = require("cmp_nvim_lsp").default_capabilities(),
settings = { settings = {
basedpyright = { basedpyright = {
analysis = { analysis = {

View File

@ -1,5 +1,4 @@
return{ return{
capabilities = require('cmp_nvim_lsp').default_capabilities(),
on_attach = function() on_attach = function()
G.api.nvim_create_user_command('R', G.run_cmd('sh %'), {}) G.api.nvim_create_user_command('R', G.run_cmd('sh %'), {})
end end

View File

@ -1,5 +1,4 @@
return { return {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
on_attach = function() on_attach = function()
G.api.nvim_create_user_command('R', G.run_cmd('g++ "%" -o "%<" && ./"%<" && rm "%<"'), {}) G.api.nvim_create_user_command('R', G.run_cmd('g++ "%" -o "%<" && ./"%<" && rm "%<"'), {})
end end

View File

@ -1,5 +1,4 @@
return { return {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
on_attach = function() on_attach = function()
G.api.nvim_create_user_command('R', G.run_cmd('go run %'), {}) 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'), {}) G.api.nvim_create_user_command('Rgin', G.run_cmd('go run ./main.go'), {})

View File

@ -1,3 +1 @@
return { return {}
capabilities = require('cmp_nvim_lsp').default_capabilities(),
}

View File

@ -5,8 +5,6 @@ table.insert(runtime_path, "lua/?/init.lua")
return { return {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
settings = { settings = {
Lua = { Lua = {

View File

@ -1,5 +1,4 @@
return { return {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
settings = { settings = {
yaml = { yaml = {
schemas = { schemas = {

View File

@ -1,4 +1,3 @@
--
G.opt.ttimeout = true G.opt.ttimeout = true
G.opt.ttimeoutlen = 100 G.opt.ttimeoutlen = 100
@ -39,15 +38,8 @@ G.opt.wrap = false
G.cmd("filetype plugin indent on") G.cmd("filetype plugin indent on")
-- 取消换行注释 -- 取消换行注释
G.au({ "BufEnter" }, { G.opt.formatoptions = G.opt.formatoptions - "o" + "r"
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" }, { G.au({ "InsertEnter" }, {
pattern = { "*" }, pattern = { "*" },

View File

@ -7,6 +7,6 @@ return {
require('plugs.winbar'), require('plugs.winbar'),
require('plugs.nvimtree'), require('plugs.nvimtree'),
require('plugs.theme'), require('plugs.theme'),
require("plugs.edit-plugs"), require('plugs.edit-plugs'),
require("plugs.dev"), require('plugs.dev'),
} }

View File

@ -13,7 +13,6 @@ return {
{ {
'terryma/vim-multiple-cursors', 'terryma/vim-multiple-cursors',
}, },
{
--格式整理 --格式整理
{ {
'junegunn/vim-easy-align', 'junegunn/vim-easy-align',
@ -24,20 +23,17 @@ return {
}) })
end end
}, },
}, -- 注释插件neovim 0.12 内置 gc用 treesitter先注释测试
{ -- {
-- 注释插件 -- 'tpope/vim-commentary',
{ -- },
'tpope/vim-commentary',
}
},
{ {
'github/copilot.vim', -- github copilot 'github/copilot.vim', -- github copilot
event = "InsertEnter",
}, },
{ {
'windwp/nvim-autopairs', 'windwp/nvim-autopairs',
event = "InsertEnter", event = "InsertEnter",
opts = {}, -- this is equalent to setup({}) function
config = function() config = function()
require('nvim-autopairs').setup({ require('nvim-autopairs').setup({
disable_filetype = { "vim" }, disable_filetype = { "vim" },
@ -69,7 +65,6 @@ return {
"f", "F", "t", "T", "f", "F", "t", "T",
"<c-f>" "<c-f>"
}, },
lazy = true,
config = function() config = function()
require("hop").setup { keys = 'asdfghjkl;' } require("hop").setup { keys = 'asdfghjkl;' }
local hop = require('hop') local hop = require('hop')

View File

@ -18,7 +18,7 @@ return {
}, },
config = function() config = function()
local has_words_before = 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)) 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 return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil
end end
@ -43,17 +43,17 @@ return {
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
["<CR>"] = cmp.mapping({ ["<CR>"] = 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) c = function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
else else
fallback() fallback()
end end
end, end,
}), }),
["<Tab>"] = cmp.mapping(function(fallback) ["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then elseif vim.fn["vsnip#available"](1) == 1 then
@ -65,7 +65,7 @@ return {
end end
end, { "i", "s" }), end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function() ["<C-p>"] = cmp.mapping(function()
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then elseif vim.fn["vsnip#jumpable"](-1) == 1 then

View File

@ -19,7 +19,9 @@ return {
jsonls = require('lsp.json'), jsonls = require('lsp.json'),
} }
local capabilities = require('cmp_nvim_lsp').default_capabilities()
for server, config in pairs(servers) do for server, config in pairs(servers) do
config.capabilities = capabilities
vim.lsp.config(server, config) vim.lsp.config(server, config)
vim.lsp.enable(server) vim.lsp.enable(server)
end end

View File

@ -1,7 +1,7 @@
return { return {
"nvim-tree/nvim-tree.lua", "nvim-tree/nvim-tree.lua",
dependencies = { dependencies = {
'kyazdani42/nvim-web-devicons' 'nvim-tree/nvim-web-devicons'
}, },
keys = { keys = {
"<c-e>" "<c-e>"
@ -33,8 +33,5 @@ return {
}) })
end end
} }
G.map({
{ "n", "<C-e>", ":NvimTreeToggle<CR>", { noremap = true } },
})
end end
} }

View File

@ -20,7 +20,7 @@ return {
wrap = false, wrap = false,
keymaps = { keymaps = {
close = { "<Esc>", "q" }, close = { "<Esc>", "q" },
goto_location = "<Cr>", goto_location = "<CR>",
focus_location = "h", focus_location = "h",
hover_symbol = "<C-space>", hover_symbol = "<C-space>",
toggle_preview = "K", toggle_preview = "K",

View File

@ -7,8 +7,7 @@ return {
end end
}, },
{ {
-- line插件 -- 状态栏
'kdheepak/tabline.nvim',
'nvim-lualine/lualine.nvim', 'nvim-lualine/lualine.nvim',
config = function() config = function()
require('lualine').setup { require('lualine').setup {
@ -17,10 +16,6 @@ return {
theme = 'auto', theme = 'auto',
component_separators = { left = '', right = '' }, component_separators = { left = '', right = '' },
section_separators = { left = '', right = '' }, section_separators = { left = '', right = '' },
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {}, ignore_focus = {},
always_divide_middle = true, always_divide_middle = true,
globalstatus = false, globalstatus = false,
@ -50,27 +45,26 @@ return {
lualine_y = {}, lualine_y = {},
lualine_z = {} lualine_z = {}
}, },
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
} }
end,
},
{
-- 标签栏
'kdheepak/tabline.nvim',
config = function()
require('tabline').setup { require('tabline').setup {
-- Defaults configuration options
enable = true, enable = true,
options = { 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 = { ' ', ' ' }, section_separators = { ' ', ' ' },
component_separators = { '', '' }, component_separators = { '', '' },
max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 max_bufferline_percent = 66,
show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named show_tabs_always = false,
show_devicons = true, -- this shows devicons in buffer section show_devicons = true,
show_bufnr = false, -- this appends [bufnr] to buffer section, show_bufnr = false,
show_filename_only = true, -- shows base filename only instead of relative path in filename show_filename_only = true,
modified_icon = "+ ", -- change the default modified icon modified_icon = "+ ",
modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified modified_italic = false,
show_tabs_only = false, -- this shows only tabs instead of tabs + buffers show_tabs_only = false,
}, },
} }
G.cmd [[ G.cmd [[

View File

@ -4,15 +4,6 @@ return {
'nvim-treesitter/nvim-treesitter', 'nvim-treesitter/nvim-treesitter',
config = function() config = function()
local treesitter_opt = { local treesitter_opt = {
ensure_installed = {
-- "c",
-- "cpp",
-- "python",
-- "java",
-- "lua",
-- "bash",
-- "vimdoc",
},
indent = { enable = true }, indent = { enable = true },
ignore_install = { ignore_install = {
"txt" "txt"

View File

@ -14,7 +14,7 @@ return {
}, },
icons = { icons = {
seperator = '>', separator = '>',
editor_state = '', editor_state = '',
lock_icon = '', lock_icon = '',
}, },

View File

@ -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:<leader>}', '${3:cmd}', { noremap = true } },"
},
"mapl": {
"prefix": "mapl",
"body": [
"{ '${1:n}', '${2:<leader>}',",
" 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:<leader>}', '${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,",
"})"
]
}
} }