autocmds.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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", USER_CONFIG_PATH, "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=terraform" },
  39. { "BufRead", "*.tf", "setlocal filetype=terraform" },
  40. { "BufNewFile", "*.tf", "setlocal filetype=terraform" },
  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 run PackerCompile after writing plugins.lua
  66. { "BufWritePost", "plugins.lua", "PackerCompile" },
  67. },
  68. _general_lsp = {
  69. { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
  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