init.lua 3.8 KB

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