summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/helpers/autocmds.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/helpers/autocmds.lua')
-rw-r--r--.config/nvim/lua/helpers/autocmds.lua127
1 files changed, 127 insertions, 0 deletions
diff --git a/.config/nvim/lua/helpers/autocmds.lua b/.config/nvim/lua/helpers/autocmds.lua
index 11f4480..7461090 100644
--- a/.config/nvim/lua/helpers/autocmds.lua
+++ b/.config/nvim/lua/helpers/autocmds.lua
@@ -29,3 +29,130 @@ vim.api.nvim_create_autocmd("VimResized", {
29 }, 29 },
30 command = "wincmd =", 30 command = "wincmd =",
31}) 31})
32
33-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
34-- Set typst filetype
35vim.api.nvim_create_autocmd(
36 {
37 "BufNewFile",
38 "BufRead",
39 },
40 {
41 group = augroup("typst"),
42 pattern = "*.typ",
43 callback = function()
44 local buf = vim.api.nvim_get_current_buf()
45 vim.api.nvim_set_option_value("filetype", "typst", { buf = buf })
46 vim.api.nvim_set_option_value("shiftwidth", 2, { buf = buf })
47 end
48 }
49)
50
51-- Set PKGBUILD filetype
52vim.api.nvim_create_autocmd(
53 {
54 "BufNewFile",
55 "BufRead",
56 },
57 {
58 group = augroup("pkgbuild"),
59 pattern = "PKGBUILD",
60 callback = function()
61 local buf = vim.api.nvim_get_current_buf()
62 vim.api.nvim_set_option_value("filetype", "PKGBUILD", { buf = buf })
63 end
64 }
65)
66
67-- Set buku-edit filetype
68vim.api.nvim_create_autocmd(
69 {
70 "BufNewFile",
71 "BufRead",
72 },
73 {
74 group = augroup("buku-edit"),
75 pattern = "buku-edit-*",
76 callback = function()
77 local buf = vim.api.nvim_get_current_buf()
78 vim.api.nvim_set_option_value("filetype", "buku", { buf = buf })
79 end
80 }
81)
82
83-- Set mail filetype
84vim.api.nvim_create_autocmd(
85 {
86 "BufNewFile",
87 "BufRead",
88 },
89 {
90 group = augroup("mail"),
91 pattern = "/tmp/neomutt*",
92 callback = function()
93 local buf = vim.api.nvim_get_current_buf()
94 vim.api.nvim_set_option_value("autoindent", false, { buf = buf })
95 vim.api.nvim_set_option_value("filetype", "mail", { buf = buf })
96 vim.api.nvim_set_option_value("wrapmargin", 0, { buf = buf })
97 vim.api.nvim_set_option_value("textwidth", 80, { buf = buf })
98 end
99 }
100)
101
102-- Resize splits if window got resized
103vim.api.nvim_create_autocmd({ "VimResized" }, {
104 group = augroup("resize_splits"),
105 callback = function()
106 local current_tab = vim.fn.tabpagenr()
107 vim.cmd("tabdo wincmd =")
108 vim.cmd("tabnext " .. current_tab)
109 end,
110})
111
112-- close some filetypes with <q>
113vim.api.nvim_create_autocmd("FileType", {
114 group = augroup("close_with_q"),
115 pattern = {
116 "PlenaryTestPopup",
117 "checkhealth",
118 "dbout",
119 "gitsigns-blame",
120 "grug-far",
121 "help",
122 "lspinfo",
123 "neotest-output",
124 "neotest-output-panel",
125 "neotest-summary",
126 "notify",
127 "qf",
128 "snacks_win",
129 "spectre_panel",
130 "startuptime",
131 "tsplayground",
132 },
133 callback = function(event)
134 vim.bo[event.buf].buflisted = false
135 vim.schedule(function()
136 vim.keymap.set("n", "q", function()
137 vim.cmd("close")
138 pcall(vim.api.nvim_buf_delete, event.buf, { force = true })
139 end, {
140 buffer = event.buf,
141 silent = true,
142 desc = "Quit buffer",
143 })
144 end)
145 end,
146})
147
148-- Auto create dir when saving a file, in case some intermediate directory does not exist
149vim.api.nvim_create_autocmd({ "BufWritePre" }, {
150 group = augroup("auto_create_dir"),
151 callback = function(event)
152 if event.match:match("^%w%w+:[\\/][\\/]") then
153 return
154 end
155 local file = vim.uv.fs_realpath(event.match) or event.match
156 vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
157 end,
158})