init.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. local lv_utils = {}
  2. function lv_utils.define_augroups(definitions) -- {{{1
  3. -- Create autocommand groups based on the passed definitions
  4. --
  5. -- The key will be the name of the group, and each definition
  6. -- within the group should have:
  7. -- 1. Trigger
  8. -- 2. Pattern
  9. -- 3. Text
  10. -- just like how they would normally be defined from Vim itself
  11. for group_name, definition in pairs(definitions) do
  12. vim.cmd("augroup " .. group_name)
  13. vim.cmd "autocmd!"
  14. for _, def in pairs(definition) do
  15. local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ")
  16. vim.cmd(command)
  17. end
  18. vim.cmd "augroup END"
  19. end
  20. end
  21. lv_utils.define_augroups {
  22. _user_autocommands = O.user_autocommands,
  23. _general_settings = {
  24. {
  25. "TextYankPost",
  26. "*",
  27. "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})",
  28. },
  29. {
  30. "BufWinEnter",
  31. "*",
  32. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  33. },
  34. {
  35. "BufRead",
  36. "*",
  37. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  38. },
  39. {
  40. "BufNewFile",
  41. "*",
  42. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  43. },
  44. { "VimLeavePre", "*", "set title set titleold=" },
  45. },
  46. -- _solidity = {
  47. -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'},
  48. -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'}
  49. -- },
  50. -- _gemini = {
  51. -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'},
  52. -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'}
  53. -- },
  54. _markdown = {
  55. { "FileType", "markdown", "setlocal wrap" },
  56. { "FileType", "markdown", "setlocal spell" },
  57. },
  58. _buffer_bindings = {
  59. { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
  60. },
  61. _auto_resize = {
  62. -- will cause split windows to be resized evenly if main window is resized
  63. {'VimResized ', '*', 'wincmd ='},
  64. },
  65. -- _mode_switching = {
  66. -- -- will switch between absolute and relative line numbers depending on mode
  67. -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'},
  68. -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'},
  69. -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'},
  70. -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'},
  71. -- },
  72. }
  73. return lv_utils
  74. -- TODO find a new home for these autocommands