autocmds.lua 3.5 KB

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