init.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. local nv_utils = {}
  2. function nv_utils.define_augroups(definitions) -- {{{1
  3. -- Create autocommand groups based on the passed definitions
  4. --
  5. -- The key will be the name of the group, and each definition
  6. -- within the group should have:
  7. -- 1. Trigger
  8. -- 2. Pattern
  9. -- 3. Text
  10. -- just like how they would normally be defined from Vim itself
  11. for group_name, definition in pairs(definitions) do
  12. vim.cmd('augroup ' .. group_name)
  13. vim.cmd('autocmd!')
  14. for _, def in pairs(definition) do
  15. local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
  16. vim.cmd(command)
  17. end
  18. vim.cmd('augroup END')
  19. end
  20. end
  21. nv_utils.define_augroups({
  22. _general_settings = {
  23. {
  24. 'TextYankPost', '*',
  25. 'lua require(\'vim.highlight\').on_yank({higroup = \'QuickScopePrimary\', timeout = 200})'
  26. }, {'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  27. {'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  28. {'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  29. {'FileType', 'java', 'luafile ~/.config/nvim/lua/lsp/java-ls.lua'},
  30. {'FileType', 'java', 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'},
  31. {'FileType', 'java', 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'}
  32. -- {'User', 'GoyoLeave', 'lua require(\'galaxyline\').disable_galaxyline()'},
  33. -- {'User', 'GoyoEnter', 'lua require(\'galaxyline\').galaxyline_augroup()'},
  34. }
  35. })
  36. -- Add this to lightbulb, java makes this annoying tho
  37. -- autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()
  38. -- lsp
  39. function nv_utils.add_to_workspace_folder()
  40. vim.lsp.buf.add_workspace_folder()
  41. end
  42. function nv_utils.clear_references()
  43. vim.lsp.buf.clear_references()
  44. end
  45. function nv_utils.code_action()
  46. vim.lsp.buf.code_action()
  47. end
  48. function nv_utils.declaration()
  49. vim.lsp.buf.declaration()
  50. vim.lsp.buf.clear_references()
  51. end
  52. function nv_utils.definition()
  53. vim.lsp.buf.definition()
  54. vim.lsp.buf.clear_references()
  55. end
  56. function nv_utils.document_highlight()
  57. vim.lsp.buf.document_highlight()
  58. end
  59. function nv_utils.document_symbol()
  60. vim.lsp.buf.document_symbol()
  61. end
  62. function nv_utils.formatting()
  63. vim.lsp.buf.formatting()
  64. end
  65. function nv_utils.formatting_sync()
  66. vim.lsp.buf.formatting_sync()
  67. end
  68. function nv_utils.hover()
  69. vim.lsp.buf.hover()
  70. end
  71. function nv_utils.implementation()
  72. vim.lsp.buf.implementation()
  73. end
  74. function nv_utils.incoming_calls()
  75. vim.lsp.buf.incoming_calls()
  76. end
  77. function nv_utils.list_workspace_folders()
  78. vim.lsp.buf.list_workspace_folders()
  79. end
  80. function nv_utils.outgoing_calls()
  81. vim.lsp.buf.outgoing_calls()
  82. end
  83. function nv_utils.range_code_action()
  84. vim.lsp.buf.range_code_action()
  85. end
  86. function nv_utils.range_formatting()
  87. vim.lsp.buf.range_formatting()
  88. end
  89. function nv_utils.references()
  90. vim.lsp.buf.references()
  91. vim.lsp.buf.clear_references()
  92. end
  93. function nv_utils.remove_workspace_folder()
  94. vim.lsp.buf.remove_workspace_folder()
  95. end
  96. function nv_utils.rename()
  97. vim.lsp.buf.rename()
  98. end
  99. function nv_utils.signature_help()
  100. vim.lsp.buf.signature_help()
  101. end
  102. function nv_utils.type_definition()
  103. vim.lsp.buf.type_definition()
  104. end
  105. function nv_utils.workspace_symbol()
  106. vim.lsp.buf.workspace_symbol()
  107. end
  108. -- diagnostic
  109. function nv_utils.get_all()
  110. vim.lsp.diagnostic.get_all()
  111. end
  112. function nv_utils.get_next()
  113. vim.lsp.diagnostic.get_next()
  114. end
  115. function nv_utils.get_prev()
  116. vim.lsp.diagnostic.get_prev()
  117. end
  118. function nv_utils.goto_next()
  119. vim.lsp.diagnostic.goto_next()
  120. end
  121. function nv_utils.goto_prev()
  122. vim.lsp.diagnostic.goto_prev()
  123. end
  124. function nv_utils.show_line_diagnostics()
  125. vim.lsp.diagnostic.show_line_diagnostics()
  126. end
  127. -- git signs
  128. function nv_utils.next_hunk()
  129. require('gitsigns').next_hunk()
  130. end
  131. function nv_utils.prev_hunk()
  132. require('gitsigns').prev_hunk()
  133. end
  134. function nv_utils.stage_hunk()
  135. require('gitsigns').stage_hunk()
  136. end
  137. function nv_utils.undo_stage_hunk()
  138. require('gitsigns').undo_stage_hunk()
  139. end
  140. function nv_utils.reset_hunk()
  141. require('gitsigns').reset_hunk()
  142. end
  143. function nv_utils.reset_buffer()
  144. require('gitsigns').reset_buffer()
  145. end
  146. function nv_utils.preview_hunk()
  147. require('gitsigns').preview_hunk()
  148. end
  149. function nv_utils.blame_line()
  150. require('gitsigns').blame_line()
  151. end
  152. -- misc
  153. -- autoformat
  154. -- autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 1000)
  155. return nv_utils