autocmds.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. _git = {
  59. { "FileType", "gitcommit", "setlocal wrap" },
  60. { "FileType", "gitcommit", "setlocal spell" },
  61. },
  62. _markdown = {
  63. { "FileType", "markdown", "setlocal wrap" },
  64. { "FileType", "markdown", "setlocal spell" },
  65. },
  66. _buffer_bindings = {
  67. { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
  68. },
  69. _auto_resize = {
  70. -- will cause split windows to be resized evenly if main window is resized
  71. { "VimResized", "*", "wincmd =" },
  72. },
  73. _packer_compile = {
  74. -- will run PackerCompile after writing plugins.lua
  75. { "BufWritePost", "plugins.lua", "PackerCompile" },
  76. },
  77. _general_lsp = {
  78. { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
  79. },
  80. -- _fterm_lazygit = {
  81. -- -- will cause esc key to exit lazy git
  82. -- {"TermEnter", "*", "call LazyGitNativation()"}
  83. -- },
  84. -- _mode_switching = {
  85. -- -- will switch between absolute and relative line numbers depending on mode
  86. -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'},
  87. -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'},
  88. -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'},
  89. -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'},
  90. -- },
  91. custom_groups = {},
  92. }
  93. function autocommands.define_augroups(definitions) -- {{{1
  94. -- Create autocommand groups based on the passed definitions
  95. --
  96. -- The key will be the name of the group, and each definition
  97. -- within the group should have:
  98. -- 1. Trigger
  99. -- 2. Pattern
  100. -- 3. Text
  101. -- just like how they would normally be defined from Vim itself
  102. for group_name, definition in pairs(definitions) do
  103. vim.cmd("augroup " .. group_name)
  104. vim.cmd "autocmd!"
  105. for _, def in pairs(definition) do
  106. local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ")
  107. vim.cmd(command)
  108. end
  109. vim.cmd "augroup END"
  110. end
  111. end
  112. return autocommands