utils.lua 874 B

1234567891011121314151617181920212223242526272829
  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. },
  24. }
  25. )