autocmds.lua 3.6 KB

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