init.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. local lv_utils = {}
  2. function lv_utils.reload_lv_config()
  3. vim.cmd "source ~/.config/nvim/lua/keymappings.lua"
  4. vim.cmd "source ~/.config/nvim/lv-config.lua"
  5. vim.cmd "source ~/.config/nvim/lua/plugins.lua"
  6. vim.cmd "source ~/.config/nvim/lua/settings.lua"
  7. vim.cmd "source ~/.config/nvim/lua/core/formatter.lua"
  8. vim.cmd ":PackerCompile"
  9. vim.cmd ":PackerInstall"
  10. -- vim.cmd ":PackerClean"
  11. end
  12. function lv_utils.check_lsp_client_active(name)
  13. local clients = vim.lsp.get_active_clients()
  14. for _, client in pairs(clients) do
  15. if client.name == name then
  16. return true
  17. end
  18. end
  19. return false
  20. end
  21. function lv_utils.define_augroups(definitions) -- {{{1
  22. -- Create autocommand groups based on the passed definitions
  23. --
  24. -- The key will be the name of the group, and each definition
  25. -- within the group should have:
  26. -- 1. Trigger
  27. -- 2. Pattern
  28. -- 3. Text
  29. -- just like how they would normally be defined from Vim itself
  30. for group_name, definition in pairs(definitions) do
  31. vim.cmd("augroup " .. group_name)
  32. vim.cmd "autocmd!"
  33. for _, def in pairs(definition) do
  34. local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ")
  35. vim.cmd(command)
  36. end
  37. vim.cmd "augroup END"
  38. end
  39. end
  40. function lv_utils.unrequire(m)
  41. package.loaded[m] = nil
  42. _G[m] = nil
  43. end
  44. lv_utils.define_augroups {
  45. _general_settings = {
  46. {
  47. "TextYankPost",
  48. "*",
  49. "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})",
  50. },
  51. {
  52. "BufWinEnter",
  53. "*",
  54. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  55. },
  56. {
  57. "BufWinEnter",
  58. "dashboard",
  59. "setlocal cursorline signcolumn=yes cursorcolumn number",
  60. },
  61. {
  62. "BufRead",
  63. "*",
  64. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  65. },
  66. {
  67. "BufNewFile",
  68. "*",
  69. "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
  70. },
  71. { "BufWritePost", "lv-config.lua", "lua require('lv-utils').reload_lv_config()" },
  72. -- { "VimLeavePre", "*", "set title set titleold=" },
  73. },
  74. _solidity = {
  75. { "BufWinEnter", ".tf", "setlocal filetype=hcl" },
  76. { "BufRead", "*.tf", "setlocal filetype=hcl" },
  77. { "BufNewFile", "*.tf", "setlocal filetype=hcl" },
  78. },
  79. -- _solidity = {
  80. -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'},
  81. -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'}
  82. -- },
  83. -- _gemini = {
  84. -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'},
  85. -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'}
  86. -- },
  87. _markdown = {
  88. { "FileType", "markdown", "setlocal wrap" },
  89. { "FileType", "markdown", "setlocal spell" },
  90. },
  91. _buffer_bindings = {
  92. { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },
  93. },
  94. _auto_resize = {
  95. -- will cause split windows to be resized evenly if main window is resized
  96. { "VimResized", "*", "wincmd =" },
  97. },
  98. _packer_compile = {
  99. -- will cause split windows to be resized evenly if main window is resized
  100. { "BufWritePost", "plugins.lua", "PackerCompile" },
  101. },
  102. -- _fterm_lazygit = {
  103. -- -- will cause esc key to exit lazy git
  104. -- {"TermEnter", "*", "call LazyGitNativation()"}
  105. -- },
  106. -- _mode_switching = {
  107. -- -- will switch between absolute and relative line numbers depending on mode
  108. -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'},
  109. -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'},
  110. -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'},
  111. -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'},
  112. -- },
  113. _user_autocommands = O.user_autocommands,
  114. }
  115. vim.cmd [[
  116. function! QuickFixToggle()
  117. if empty(filter(getwininfo(), 'v:val.quickfix'))
  118. copen
  119. else
  120. cclose
  121. endif
  122. endfunction
  123. ]]
  124. return lv_utils
  125. -- TODO: find a new home for these autocommands