autocomands.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. -- Create autogroups first
  2. local MZuninoGroup = vim.api.nvim_create_augroup("mzunino", {})
  3. local yank_group = vim.api.nvim_create_augroup("HighlightYank", {})
  4. local bigfile_group = vim.api.nvim_create_augroup("bigfile", {})
  5. -- Set bigfile size threshold
  6. vim.g.bigfile_size = 1024 * 1024 * 1.5 -- 1.5 MB
  7. -- Netrw diagnostic disable
  8. vim.api.nvim_create_autocmd("FileType", {
  9. pattern = "netrw",
  10. callback = function()
  11. vim.diagnostic.enable(false)
  12. end,
  13. })
  14. -- Template files
  15. vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
  16. pattern = "*.templ",
  17. command = "set filetype=templ",
  18. })
  19. -- Highlight on yank
  20. vim.api.nvim_create_autocmd("TextYankPost", {
  21. group = yank_group,
  22. pattern = "*",
  23. callback = function()
  24. vim.highlight.on_yank({
  25. higroup = "IncSearch",
  26. timeout = 40,
  27. })
  28. end,
  29. })
  30. -- Remove trailing whitespace on save
  31. vim.api.nvim_create_autocmd("BufWritePre", {
  32. group = MZuninoGroup,
  33. pattern = "*",
  34. command = [[%s/\s\+$//e]],
  35. })
  36. -- Bigfile detection
  37. vim.filetype.add({
  38. pattern = {
  39. [".*"] = {
  40. function(path, buf)
  41. return vim.bo[buf].filetype ~= "bigfile" and path and vim.fn.getfsize(path) > vim.g.bigfile_size and "bigfile"
  42. or nil
  43. end,
  44. },
  45. },
  46. })
  47. -- Bigfile handling
  48. vim.api.nvim_create_autocmd("FileType", {
  49. group = bigfile_group,
  50. pattern = "bigfile",
  51. callback = function(ev)
  52. vim.b.minianimate_disable = true
  53. vim.schedule(function()
  54. vim.bo[ev.buf].syntax = vim.filetype.match({ buf = ev.buf }) or ""
  55. end)
  56. end,
  57. })