init.lua 4.0 KB

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