init.lua 3.8 KB

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