autocmds.lua 3.9 KB

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