utils.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. {'FileType', 'java', 'luafile ~/.config/nvim/lua/lsp/java-ls.lua'},
  27. {'FileType', 'java', 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'},
  28. {'FileType', 'lua', 'lua print("hi")'},
  29. --{'BufRead', '*', 'lua vim.api.nvim_buf_set_option(0, "commentstring", "{/*%s*/}")'},
  30. --{'BufNewFile', '*', 'lua vim.api.nvim_buf_set_option(0, "commentstring", "{/*%s*/}")'},
  31. {'BufNewFile', '*', 'verbose setlocal commentstring="{/*%s*/}"'},
  32. {'BufRead', '*', 'verbose setlocal commentstring="{/*%s*/}"'},
  33. },
  34. }
  35. )
  36. -- Add this to lightbulb, java makes this annoying tho
  37. -- autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()