autocmds.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. local autocommands = {}
  2. lvim.autocommands = {
  3. _general_settings = {
  4. {
  5. "TextYankPost",
  6. "*",
  7. "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})",
  8. },
  9. {
  10. "BufWinEnter",
  11. "*",
  12. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  13. },
  14. {
  15. "BufWinEnter",
  16. "dashboard",
  17. "setlocal cursorline signcolumn=yes cursorcolumn number",
  18. },
  19. {
  20. "BufRead",
  21. "*",
  22. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  23. },
  24. {
  25. "BufNewFile",
  26. "*",
  27. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  28. },
  29. { "BufWritePost", "lv-config.lua", "lua require('utils').reload_lv_config()" },
  30. {
  31. "FileType",
  32. "qf",
  33. "set nobuflisted",
  34. },
  35. -- { "VimLeavePre", "*", "set title set titleold=" },
  36. },
  37. _filetypechanges = {
  38. { "BufWinEnter", ".tf", "setlocal filetype=hcl" },
  39. { "BufRead", "*.tf", "setlocal filetype=hcl" },
  40. { "BufNewFile", "*.tf", "setlocal filetype=hcl" },
  41. { "BufWinEnter", ".zsh", "setlocal filetype=sh" },
  42. { "BufRead", "*.zsh", "setlocal filetype=sh" },
  43. { "BufNewFile", "*.zsh", "setlocal filetype=sh" },
  44. },
  45. -- _solidity = {
  46. -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'},
  47. -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'}
  48. -- },
  49. -- _gemini = {
  50. -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'},
  51. -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'}
  52. -- },
  53. _markdown = {
  54. { "FileType", "markdown", "setlocal wrap" },
  55. { "FileType", "markdown", "setlocal spell" },
  56. },
  57. _buffer_bindings = {
  58. { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
  59. },
  60. _auto_resize = {
  61. -- will cause split windows to be resized evenly if main window is resized
  62. { "VimResized", "*", "wincmd =" },
  63. },
  64. _packer_compile = {
  65. -- will cause split windows to be resized evenly if main window is resized
  66. { "BufWritePost", "plugins.lua", "PackerCompile" },
  67. },
  68. -- _fterm_lazygit = {
  69. -- -- will cause esc key to exit lazy git
  70. -- {"TermEnter", "*", "call LazyGitNativation()"}
  71. -- },
  72. -- _mode_switching = {
  73. -- -- will switch between absolute and relative line numbers depending on mode
  74. -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'},
  75. -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'},
  76. -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'},
  77. -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'},
  78. -- },
  79. custom_groups = {},
  80. }
  81. function autocommands.define_augroups(definitions) -- {{{1
  82. -- Create autocommand groups based on the passed definitions
  83. --
  84. -- The key will be the name of the group, and each definition
  85. -- within the group should have:
  86. -- 1. Trigger
  87. -- 2. Pattern
  88. -- 3. Text
  89. -- just like how they would normally be defined from Vim itself
  90. for group_name, definition in pairs(definitions) do
  91. vim.cmd("augroup " .. group_name)
  92. vim.cmd "autocmd!"
  93. for _, def in pairs(definition) do
  94. local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ")
  95. vim.cmd(command)
  96. end
  97. vim.cmd "augroup END"
  98. end
  99. end
  100. return autocommands