autocmds.lua 4.0 KB

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