summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/config/autocmd.lua
diff options
context:
space:
mode:
authormoxie <moxie.git@posteo.net>2025-09-30 12:27:44 +0300
committermoxie <moxie.git@posteo.net>2025-09-30 12:27:44 +0300
commit1e27d1c7b25e4d28a25c0fa2c4e6e33a66b9072e (patch)
tree7169509b4d5dfce3ed25fe333cc506a40f5c90f2 /.config/nvim/lua/config/autocmd.lua
parent51797f743fe74d1723ca62085f92e8c5e953038b (diff)
add nvim configs
Diffstat (limited to '.config/nvim/lua/config/autocmd.lua')
-rw-r--r--.config/nvim/lua/config/autocmd.lua83
1 files changed, 83 insertions, 0 deletions
diff --git a/.config/nvim/lua/config/autocmd.lua b/.config/nvim/lua/config/autocmd.lua
new file mode 100644
index 0000000..9cdb78d
--- /dev/null
+++ b/.config/nvim/lua/config/autocmd.lua
@@ -0,0 +1,83 @@
+local au = vim.api.nvim_create_autocmd
+local augroup = vim.api.nvim_create_augroup
+local ag = augroup("default", {})
+local ft = augroup("filetypes", {})
+
+-- shortly highlight yanks
+au("TextYankPost", {
+ group = ag,
+ pattern = "*",
+ callback = function()
+ vim.highlight.on_yank({ higroup = "IncSearch", timeout = 250, on_visual = true })
+ end,
+})
+
+au("WinEnter", {
+ group = ag,
+ pattern = "*",
+ callback = function()
+ vim.opt_local.cursorline = true
+ end,
+})
+au("WinLeave", {
+ group = ag,
+ pattern = "*",
+ callback = function()
+ vim.opt_local.cursorline = false
+ end,
+})
+
+-- highlight extra whitespace
+local hlstmt = [[highlight ExtraWhitespace ctermbg=red guibg=red]]
+vim.cmd(hlstmt)
+au("ColorScheme", {
+ group = ag,
+ pattern = "*",
+ callback = function()
+ vim.cmd(hlstmt)
+ end,
+})
+vim.cmd([[match ExtraWhitespace /\s\+$\| \+\ze\t/]])
+
+-- only show color col in insert mode
+au("InsertEnter", {
+ group = ag,
+ pattern = "*",
+ callback = function()
+ vim.o.colorcolumn = "78"
+ end,
+})
+au("InsertLeave", {
+ group = ag,
+ pattern = "*",
+ callback = function()
+ vim.o.colorcolumn = ""
+ end,
+})
+
+-- resize splits upon window resize
+au("VimResized", {
+ group = ag,
+ pattern = "*",
+ callback = function()
+ vim.cmd([[exe "normal! \<C-w>="]])
+ end,
+})
+
+-- ms word doc reading
+au("BufReadPre", {
+ group = ft,
+ pattern = "*.doc{x,}",
+ callback = function()
+ vim.opt_local.readonly = true
+ end,
+})
+vim.cmd([[au BufReadPost *.doc %!antiword "%"]])
+vim.cmd([[au BufReadPost *.docx %!docx2txt "%" -]])
+
+-- remove whitespace at the end of line
+au({ "BufWritePre" }, {
+ group = ag,
+ pattern = "*",
+ command = [[%s/\s\+$//e]],
+})