utils.lua 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. local function define_augroups(definitions) -- {{{1
  2. -- Create autocommand groups based on the passed definitions
  3. --
  4. -- The key will be the name of the group, and each definition
  5. -- within the group should have:
  6. -- 1. Trigger
  7. -- 2. Pattern
  8. -- 3. Text
  9. -- just like how they would normally be defined from Vim itself
  10. for group_name, definition in pairs(definitions) do
  11. vim.cmd('augroup ' .. group_name)
  12. vim.cmd('autocmd!')
  13. for _, def in pairs(definition) do
  14. local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
  15. vim.cmd(command)
  16. end
  17. vim.cmd('augroup END')
  18. end
  19. end
  20. define_augroups(
  21. {_general_settings = {
  22. {'TextYankPost', '*', 'lua require(\'vim.highlight\').on_yank({higroup = \'IncSearch\', timeout = 200})'},
  23. {'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  24. {'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  25. {'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  26. },
  27. }
  28. )