init.lua 2.9 KB

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