autocmds.lua 3.8 KB

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