feat(nvim): typst; tidy language specific configurations

This commit is contained in:
2025-11-22 22:03:21 +08:00
parent 9273df1ab8
commit 4ae4f3bb2b
12 changed files with 66 additions and 147 deletions

View File

@@ -4,9 +4,6 @@ vim.api.nvim_create_autocmd("BufWritePre", {
desc = "auto format Go files",
callback = function()
vim.lsp.buf.format()
-- vim.fn.system("go fmt " .. vim.fn.expand("%:p"))
-- vim.fn.system("goimports -w " .. vim.fn.expand("%:p"))
-- vim.cmd("edit")
end,
group = "Go",
})

View File

@@ -1,5 +1 @@
require("langs.go")
-- require("langs.rust")
require("langs.lualang")
require("langs.nix")
require("langs.markdown")

View File

@@ -1,34 +0,0 @@
vim.api.nvim_create_augroup("Lua", {})
local old = {}
vim.api.nvim_create_autocmd("BufEnter", {
pattern = { "*.lua" },
desc = "auto lua file indent",
callback = function()
local opt = vim.opt
-- Tab width setting
old.tabstop = opt.tabstop
old.shiftwidth = opt.shiftwidth
old.softtabstop = opt.softtabstop
old.expandtab = opt.expandtab
opt.tabstop = 2
opt.shiftwidth = 2
opt.softtabstop = 2
opt.expandtab = true
opt.autoindent = true
end,
group = "Lua",
})
vim.api.nvim_create_autocmd("BufLeave", {
pattern = { "*.lua" },
desc = "auto lua file indent",
callback = function()
local opt = vim.opt
-- Tab width setting
opt.tabstop = old.tabstop
opt.shiftwidth = old.shiftwidth
opt.softtabstop = old.softtabstop
opt.expandtab = old.expandtab
end,
group = "Lua",
})

View File

@@ -1,34 +0,0 @@
vim.api.nvim_create_augroup("Markdown", {})
local old = {}
vim.api.nvim_create_autocmd("BufEnter", {
pattern = { "*.md" },
desc = "auto md file indent",
callback = function()
local opt = vim.opt
-- Tab width setting
old.tabstop = opt.tabstop
old.shiftwidth = opt.shiftwidth
old.softtabstop = opt.softtabstop
old.expandtab = opt.expandtab
opt.tabstop = 2
opt.shiftwidth = 2
opt.softtabstop = 2
opt.expandtab = true
opt.autoindent = true
end,
group = "Markdown",
})
vim.api.nvim_create_autocmd("BufLeave", {
pattern = { "*.md" },
desc = "auto markdown file indent",
callback = function()
local opt = vim.opt
-- Tab width setting
opt.tabstop = old.tabstop
opt.shiftwidth = old.shiftwidth
opt.softtabstop = old.softtabstop
opt.expandtab = old.expandtab
end,
group = "Markdown",
})

View File

@@ -1,34 +0,0 @@
vim.api.nvim_create_augroup("Nix", {})
local old = {}
vim.api.nvim_create_autocmd("BufEnter", {
pattern = { "*.nix" },
desc = "auto nix file indent",
callback = function()
local opt = vim.opt
-- Tab width setting
old.tabstop = opt.tabstop
old.shiftwidth = opt.shiftwidth
old.softtabstop = opt.softtabstop
old.expandtab = opt.expandtab
opt.tabstop = 2
opt.shiftwidth = 2
opt.softtabstop = 2
opt.expandtab = true
opt.autoindent = true
end,
group = "Nix",
})
vim.api.nvim_create_autocmd("BufLeave", {
pattern = { "*.nix" },
desc = "auto nix file indent",
callback = function()
local opt = vim.opt
-- Tab width setting
opt.tabstop = old.tabstop
opt.shiftwidth = old.shiftwidth
opt.softtabstop = old.softtabstop
opt.expandtab = old.expandtab
end,
group = "Nix",
})

View File

@@ -1,10 +0,0 @@
vim.api.nvim_create_augroup("Rust", {})
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.rs" },
desc = "auto format Rust files",
callback = function()
vim.fn.system("rustfmt " .. vim.fn.expand("%:p"))
vim.cmd("edit")
end,
group = "Rust",
})

View File

@@ -1,18 +1,4 @@
local servers = {
"lua_ls",
"pyright",
"gopls",
"clangd",
"rust_analyzer",
"ts_ls",
"jsonls",
"cssls",
"nixd",
"html",
"java_language_server",
}
local extra_config = {
lua_ls = {
settings = {
Lua = {
@@ -52,20 +38,30 @@ local extra_config = {
nixd = {
settings = {
nixd = {
formatting = {
command = { "nixfmt" },
},
nixpkgs = {
expr = "import <nixpkgs> { }",
},
options = {
nixos = {
expr = '(builtins.getFlake ("git+file://" + toString ./.)).nixosConfigurations.imxyy-nix.options',
},
},
},
},
},
tinymist = {
cmd = { "tinymist" },
filetypes = { "typst" },
},
qmlls = {
cmd = { "qmlls", "-E" },
},
pyright = {},
gopls = {},
clangd = {},
ts_ls = {},
jsonls = {},
cssls = {},
html = {},
java_language_server = {},
}
local capabilities = require("cmp_nvim_lsp").default_capabilities()
@@ -74,14 +70,8 @@ capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
for _, server in ipairs(servers) do
local extra = extra_config[server] or {}
local config = {
capabilities = capabilities,
}
for k, v in pairs(extra) do
config[k] = v
end
for server, config in pairs(servers) do
config["capabilities"] = capabilities
vim.lsp.config(server, config)
vim.lsp.enable(server)
end

View File

@@ -281,6 +281,12 @@ local plugins = {
ft = "pest",
opts = {},
},
{
"nmac427/guess-indent.nvim",
event = "VeryLazy",
opts = {},
},
}
require("lazy").setup(plugins, {})