init.lua 2.9 KB

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