autocmds.lua 2.6 KB

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