mirror of
https://github.com/d0zingcat/dotfiles.git
synced 2026-05-14 15:09:44 +00:00
refactor(nvim): 完整重写配置,支持 Go/Rust/Python/TypeScript 开发
- 架构重构:新增 plugins/lang/ 子目录,按语言拆分配置 - 补全引擎:nvim-cmp → blink.cmp + LuaSnip - 文件浏览:新增 neo-tree(<Space>e) - 语言支持: - Go: ray-x/go.nvim + dap-go + neotest-go - Rust: rustaceanvim + crates.nvim - Python: venv-selector + dap-python + neotest-python - TypeScript: typescript-tools.nvim(替换 ts_ls) - LSP: lazydev + mason + mason-lspconfig + fidget + inc-rename - 格式化: conform.nvim(lsp_format fallback,保存时自动格式化) - Lint: nvim-lint(selene 替换 luacheck,Mason 可直接安装) - UI: snacks.nvim(dashboard+notifier+picker)+ noice + lualine + bufferline - 编辑增强: mini.ai + mini.surround + grug-far + flash + ufo + trouble v3 - 删除废弃文件: cmp/coding/null-ls/mason/lspconfig/go/python 等旧文件 - 修复: Neovim 0.12 treesitter query 校验报错(noice routes 过滤) - 新增: NVIM_GUIDE.md 快捷键使用手册 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
78
nvim/lua/plugins/formatting.lua
Normal file
78
nvim/lua/plugins/formatting.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
-- formatting.lua - 代码格式化(conform.nvim)
|
||||
|
||||
return {
|
||||
{
|
||||
"stevearc/conform.nvim",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
cmd = { "ConformInfo" },
|
||||
keys = {
|
||||
{
|
||||
"<leader>cf",
|
||||
function()
|
||||
require("conform").format({ async = true, lsp_format = "fallback" })
|
||||
end,
|
||||
mode = { "n", "v" },
|
||||
desc = "格式化代码",
|
||||
},
|
||||
{
|
||||
"<leader>uf",
|
||||
function()
|
||||
vim.b.disable_autoformat = not vim.b.disable_autoformat
|
||||
vim.notify(
|
||||
"当前缓冲区自动格式化 " .. (vim.b.disable_autoformat and "已禁用" or "已启用"),
|
||||
vim.log.levels.INFO
|
||||
)
|
||||
end,
|
||||
desc = "切换当前缓冲区自动格式化",
|
||||
},
|
||||
{
|
||||
"<leader>uF",
|
||||
function()
|
||||
vim.g.disable_autoformat = not vim.g.disable_autoformat
|
||||
vim.notify(
|
||||
"全局自动格式化 " .. (vim.g.disable_autoformat and "已禁用" or "已启用"),
|
||||
vim.log.levels.INFO
|
||||
)
|
||||
end,
|
||||
desc = "切换全局自动格式化",
|
||||
},
|
||||
},
|
||||
opts = {
|
||||
formatters_by_ft = {
|
||||
lua = { "stylua" },
|
||||
go = { "goimports", "gofumpt" },
|
||||
rust = { "rustfmt" },
|
||||
python = { "isort", "ruff_format" },
|
||||
javascript = { "prettierd", "prettier", stop_after_first = true },
|
||||
typescript = { "prettierd", "prettier", stop_after_first = true },
|
||||
javascriptreact = { "prettierd", "prettier", stop_after_first = true },
|
||||
typescriptreact = { "prettierd", "prettier", stop_after_first = true },
|
||||
json = { "prettierd" },
|
||||
jsonc = { "prettierd" },
|
||||
html = { "prettierd" },
|
||||
css = { "prettierd" },
|
||||
scss = { "prettierd" },
|
||||
yaml = { "prettierd" },
|
||||
markdown = { "prettierd" },
|
||||
sh = { "shfmt" },
|
||||
bash = { "shfmt" },
|
||||
},
|
||||
|
||||
formatters = {
|
||||
stylua = {
|
||||
args = { "--indent-type", "Spaces", "--indent-width", "2", "-" },
|
||||
},
|
||||
shfmt = {
|
||||
args = { "-i", "2", "-" },
|
||||
},
|
||||
},
|
||||
|
||||
format_on_save = function(bufnr)
|
||||
if vim.b[bufnr].disable_autoformat or vim.g.disable_autoformat then
|
||||
return
|
||||
end
|
||||
return { timeout_ms = 3000, lsp_format = "fallback" }
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user