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:
parent
f1ed06ae9f
commit
cbf4579990
26
init.lua
26
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"
|
||||
-- 安装/定位 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",
|
||||
'git',
|
||||
'clone',
|
||||
'--filter=blob:none',
|
||||
'https://github.com/folke/lazy.nvim.git',
|
||||
'--branch=stable',
|
||||
lazypath,
|
||||
})
|
||||
end
|
||||
G.opt.rtp:prepend(lazypath)
|
||||
end
|
||||
|
||||
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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -20,20 +20,16 @@ G.map({
|
|||
{ 'n', '<A-l>', ':tabn<CR>', opt },
|
||||
{ 'n', '<A-h>', ':tabp<CR>', opt },
|
||||
|
||||
|
||||
{ 'n', '<c-j>', '<c-w>j', opt },
|
||||
{ 'n', '<c-h>', '<c-w>h', opt },
|
||||
{ 'n', '<c-k>', '<c-w>k', opt },
|
||||
{ 'n', '<c-l>', '<c-w>l', opt },
|
||||
|
||||
|
||||
{ 'n', '<c-c>', ':q<CR>', opt },
|
||||
{ 'n', '<c-S>', ':w !sudo tee %<CR>', opt },
|
||||
{ 'n', '<c-q>', ':q!<CR>', opt },
|
||||
{ 'v', '<cs-y>', '"+y', opt },
|
||||
|
||||
|
||||
|
||||
{ 'n', '<leader>y', 'ggyG', opt },
|
||||
{ 'n', '<leader>p', 'ggpG', opt },
|
||||
{ 'n', '<leader>v', 'ggVG', opt },
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
return {
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
||||
settings = {
|
||||
basedpyright = {
|
||||
analysis = {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'), {})
|
||||
|
|
|
|||
|
|
@ -1,3 +1 @@
|
|||
return {
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
}
|
||||
return {}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ table.insert(runtime_path, "lua/?/init.lua")
|
|||
|
||||
return {
|
||||
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
|
||||
settings = {
|
||||
|
||||
Lua = {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
return {
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
settings = {
|
||||
yaml = {
|
||||
schemas = {
|
||||
|
|
|
|||
|
|
@ -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 = { "*" },
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ return {
|
|||
{
|
||||
'terryma/vim-multiple-cursors',
|
||||
},
|
||||
{
|
||||
--格式整理
|
||||
{
|
||||
'junegunn/vim-easy-align',
|
||||
|
|
@ -24,20 +23,17 @@ return {
|
|||
})
|
||||
end
|
||||
},
|
||||
},
|
||||
{
|
||||
-- 注释插件
|
||||
{
|
||||
'tpope/vim-commentary',
|
||||
}
|
||||
},
|
||||
-- 注释插件(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",
|
||||
"<c-f>"
|
||||
},
|
||||
lazy = true,
|
||||
config = function()
|
||||
require("hop").setup { keys = 'asdfghjkl;' }
|
||||
local hop = require('hop')
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
||||
["<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)
|
||||
if cmp.visible() then
|
||||
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })
|
||||
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
}),
|
||||
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
["<C-n>"] = 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" }),
|
||||
|
||||
["<S-Tab>"] = cmp.mapping(function()
|
||||
["<C-p>"] = cmp.mapping(function()
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
return {
|
||||
"nvim-tree/nvim-tree.lua",
|
||||
dependencies = {
|
||||
'kyazdani42/nvim-web-devicons'
|
||||
'nvim-tree/nvim-web-devicons'
|
||||
},
|
||||
keys = {
|
||||
"<c-e>"
|
||||
|
|
@ -33,8 +33,5 @@ return {
|
|||
})
|
||||
end
|
||||
}
|
||||
G.map({
|
||||
{ "n", "<C-e>", ":NvimTreeToggle<CR>", { noremap = true } },
|
||||
})
|
||||
end
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ return {
|
|||
wrap = false,
|
||||
keymaps = {
|
||||
close = { "<Esc>", "q" },
|
||||
goto_location = "<Cr>",
|
||||
goto_location = "<CR>",
|
||||
focus_location = "h",
|
||||
hover_symbol = "<C-space>",
|
||||
toggle_preview = "K",
|
||||
|
|
|
|||
|
|
@ -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 [[
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ return {
|
|||
},
|
||||
|
||||
icons = {
|
||||
seperator = '>',
|
||||
separator = '>',
|
||||
editor_state = '●',
|
||||
lock_icon = '',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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,",
|
||||
"})"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue