nvim/lua/config/autocmds.lua
Simon Lasbrugnas 5d090eabed
Some checks failed
release-please / release-please (push) Has been cancelled
feat: add support for system light and dark mode switch
Remove xiyaowong/transparent.nvim plugin
2026-03-13 16:11:57 +01:00

95 lines
2.1 KiB
Lua

-- Enable Tree-Sitter
vim.api.nvim_create_autocmd("FileType", {
pattern = {
"c",
"html",
"javascript",
"jsx",
"lua",
"markdown",
"python",
"toml",
"tsx",
"typescript",
"vim",
"xml",
"yaml",
"go",
"gomod",
"gosum",
},
callback = function()
vim.treesitter.start()
vim.bo.syntax = "on"
end,
})
local background_group = vim.api.nvim_create_augroup("BackgroundSync", { clear = true })
local function sync_background_colorscheme()
local colorscheme = vim.o.background == "light" and "dawnfox" or "duskfox"
if vim.g.colors_name == colorscheme then
return
end
vim.cmd.colorscheme(colorscheme)
end
vim.api.nvim_create_autocmd("OptionSet", {
group = background_group,
pattern = "background",
callback = sync_background_colorscheme,
})
-- Auto insert mode on TermOpen
vim.api.nvim_create_autocmd({ "TermOpen", "BufEnter" }, {
pattern = { "*" },
callback = function()
if vim.opt.buftype:get() == "terminal" then
vim.cmd(":startinsert")
end
end,
})
-- vim-bujo auto commit & push on save
vim.api.nvim_create_augroup("BujoGit", { clear = true })
vim.api.nvim_create_autocmd("BufWritePost", {
group = "BujoGit",
pattern = vim.fn.expand("$HOME") .. "/.cache/bujo/*",
callback = function()
local filepath = vim.api.nvim_buf_get_name(0)
if filepath:match(vim.fn.expand("~/.cache/bujo/")) then
vim.fn.jobstart({
"sh",
"-c",
"cd ~/.cache/bujo && git add . && git commit -m 'Auto-update bujo files' && git push",
}, {
on_exit = function(_, code)
if code == 0 then
vim.schedule(function()
vim.notify("Bujo files committed and pushed", vim.log.levels.INFO)
end)
else
vim.schedule(function()
vim.notify("Error syncing bujo files", vim.log.levels.ERROR)
end)
end
end,
})
end
end,
})
-- Disable LSP in fugitive buffers
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
local bufnr = args.buf
if vim.api.nvim_buf_get_name(bufnr):match("^fugitive://") then
if client then
vim.lsp.stop_client(client.id)
end
end
end,
})