autocmds.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. local M = {}
  2. --- Load the default set of autogroups and autocommands.
  3. function M.load_augroups()
  4. local user_config_file = vim.fn.resolve(require("lvim.config"):get_user_config_path())
  5. return {
  6. _general_settings = {
  7. {
  8. "Filetype",
  9. "*",
  10. "lua require('lvim.utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))",
  11. },
  12. { "FileType", "qf,help,man", "nnoremap <silent> <buffer> q :close<CR>" },
  13. {
  14. "TextYankPost",
  15. "*",
  16. "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})",
  17. },
  18. {
  19. "BufWinEnter",
  20. "dashboard",
  21. "setlocal cursorline signcolumn=yes cursorcolumn number",
  22. },
  23. { "BufWritePost", user_config_file, "lua require('lvim.config'):reload()" },
  24. { "FileType", "qf", "set nobuflisted" },
  25. -- { "VimLeavePre", "*", "set title set titleold=" },
  26. },
  27. _formatoptions = {
  28. {
  29. "BufWinEnter,BufRead,BufNewFile",
  30. "*",
  31. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  32. },
  33. },
  34. _filetypechanges = {
  35. { "BufWinEnter", ".tf", "setlocal filetype=terraform" },
  36. { "BufRead", "*.tf", "setlocal filetype=terraform" },
  37. { "BufNewFile", "*.tf", "setlocal filetype=terraform" },
  38. { "BufWinEnter", ".zsh", "setlocal filetype=sh" },
  39. { "BufRead", "*.zsh", "setlocal filetype=sh" },
  40. { "BufNewFile", "*.zsh", "setlocal filetype=sh" },
  41. },
  42. _git = {
  43. { "FileType", "gitcommit", "setlocal wrap" },
  44. { "FileType", "gitcommit", "setlocal spell" },
  45. },
  46. _markdown = {
  47. { "FileType", "markdown", "setlocal wrap" },
  48. { "FileType", "markdown", "setlocal spell" },
  49. },
  50. _buffer_bindings = {
  51. { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
  52. },
  53. _auto_resize = {
  54. -- will cause split windows to be resized evenly if main window is resized
  55. { "VimResized", "*", "tabdo wincmd =" },
  56. },
  57. _general_lsp = {
  58. { "FileType", "lspinfo,lsp-installer,null-ls-info", "nnoremap <silent> <buffer> q :close<CR>" },
  59. },
  60. custom_groups = {},
  61. }
  62. end
  63. function M.define_augroups(definitions) -- {{{1
  64. -- Create autocommand groups based on the passed definitions
  65. --
  66. -- The key will be the name of the group, and each definition
  67. -- within the group should have:
  68. -- 1. Trigger
  69. -- 2. Pattern
  70. -- 3. Text
  71. -- just like how they would normally be defined from Vim itself
  72. for group_name, definition in pairs(definitions) do
  73. vim.cmd("augroup " .. group_name)
  74. vim.cmd "autocmd!"
  75. for _, def in pairs(definition) do
  76. local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ")
  77. vim.cmd(command)
  78. end
  79. vim.cmd "augroup END"
  80. end
  81. end
  82. return M