-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocmds.lua
73 lines (64 loc) · 2.55 KB
/
autocmds.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- vim.api.nvim_create_autocmd("VimLeave", {
-- desc = "Stop running auto compiler on leave",
-- group = vim.api.nvim_create_augroup("quit_autocomp", { clear = true }),
-- pattern = "*",
-- callback = function() vim.fn.jobstart { "autocomp", vim.fn.expand "%:p", "stop" } end,
-- })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
pattern = { "*.tpp" },
callback = function() vim.opt_local.filetype = "cpp" end,
})
vim.api.nvim_create_autocmd("FileType", {
desc = "Enable wrap and spell for text like documents",
group = vim.api.nvim_create_augroup("auto_spell", { clear = true }),
pattern = { "gitcommit", "markdown", "text", "plaintex" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})
vim.api.nvim_create_autocmd("FileType", {
desc = "conceal level to 2",
group = vim.api.nvim_create_augroup("neorg coneal", { clear = true }),
pattern = { "norg" },
callback = function() vim.opt.conceallevel = 2 end,
})
vim.api.nvim_create_autocmd("User", {
desc = "Auto hide tabline",
group = vim.api.nvim_create_augroup("autohide_tabline", { clear = true }),
pattern = "AstroBufsUpdated",
callback = function()
local new_showtabline = #vim.t.bufs > 1 and 2 or 1
if new_showtabline ~= vim.opt.showtabline:get() then vim.opt.showtabline = new_showtabline end
end,
})
if vim.env.KITTY_LISTEN_ON then
local cmd = require("astronvim.utils").cmd
for _, color in ipairs(vim.fn.split(cmd { "kitty", "@", "get-colors" } or "", "\n")) do
local orig_bg = color:match "^background%s+(#[0-9a-fA-F]+)$"
if orig_bg then
local function set_bg(new_color) cmd { "kitty", "@", "set-colors", ("background=%s"):format(new_color) } end
local augroup = vim.api.nvim_create_augroup("kitty_background", { clear = true })
vim.api.nvim_create_autocmd("User", {
desc = "set kitty background to colorscheme's background",
pattern = "AstroColorScheme",
group = augroup,
callback = function()
local bg_color = require("astronvim.utils").get_hlgroup("Normal").bg
if not bg_color or bg_color == "NONE" then
bg_color = orig_bg
elseif type(bg_color) == "number" then
bg_color = string.format("#%06x", bg_color)
end
set_bg(bg_color)
end,
})
vim.api.nvim_create_autocmd("VimLeave", {
desc = "set kitty background back to original background",
group = augroup, -- add autocmd to augroup
callback = function() set_bg(orig_bg) end,
})
break
end
end
end