autocomands.lua 1.1 KB

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