init.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 = \'Search\', 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. {'FileType', 'markdown', 'set wrap'}
  33. -- {'User', 'GoyoLeave', 'lua require(\'galaxyline\').disable_galaxyline()'},
  34. -- {'User', 'GoyoEnter', 'lua require(\'galaxyline\').galaxyline_augroup()'},
  35. }
  36. })
  37. -- Add this to lightbulb, java makes this annoying tho
  38. -- autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()
  39. -- lsp
  40. function nv_utils.add_to_workspace_folder()
  41. vim.lsp.buf.add_workspace_folder()
  42. end
  43. function nv_utils.clear_references()
  44. vim.lsp.buf.clear_references()
  45. end
  46. function nv_utils.code_action()
  47. vim.lsp.buf.code_action()
  48. end
  49. function nv_utils.declaration()
  50. vim.lsp.buf.declaration()
  51. vim.lsp.buf.clear_references()
  52. end
  53. function nv_utils.definition()
  54. vim.lsp.buf.definition()
  55. vim.lsp.buf.clear_references()
  56. end
  57. function nv_utils.document_highlight()
  58. vim.lsp.buf.document_highlight()
  59. end
  60. function nv_utils.document_symbol()
  61. vim.lsp.buf.document_symbol()
  62. end
  63. function nv_utils.formatting()
  64. vim.lsp.buf.formatting()
  65. end
  66. function nv_utils.formatting_sync()
  67. vim.lsp.buf.formatting_sync()
  68. end
  69. function nv_utils.hover()
  70. vim.lsp.buf.hover()
  71. end
  72. function nv_utils.implementation()
  73. vim.lsp.buf.implementation()
  74. end
  75. function nv_utils.incoming_calls()
  76. vim.lsp.buf.incoming_calls()
  77. end
  78. function nv_utils.list_workspace_folders()
  79. vim.lsp.buf.list_workspace_folders()
  80. end
  81. function nv_utils.outgoing_calls()
  82. vim.lsp.buf.outgoing_calls()
  83. end
  84. function nv_utils.range_code_action()
  85. vim.lsp.buf.range_code_action()
  86. end
  87. function nv_utils.range_formatting()
  88. vim.lsp.buf.range_formatting()
  89. end
  90. function nv_utils.references()
  91. vim.lsp.buf.references()
  92. vim.lsp.buf.clear_references()
  93. end
  94. function nv_utils.remove_workspace_folder()
  95. vim.lsp.buf.remove_workspace_folder()
  96. end
  97. function nv_utils.rename()
  98. vim.lsp.buf.rename()
  99. end
  100. function nv_utils.signature_help()
  101. vim.lsp.buf.signature_help()
  102. end
  103. function nv_utils.type_definition()
  104. vim.lsp.buf.type_definition()
  105. end
  106. function nv_utils.workspace_symbol()
  107. vim.lsp.buf.workspace_symbol()
  108. end
  109. -- diagnostic
  110. function nv_utils.get_all()
  111. vim.lsp.diagnostic.get_all()
  112. end
  113. function nv_utils.get_next()
  114. vim.lsp.diagnostic.get_next()
  115. end
  116. function nv_utils.get_prev()
  117. vim.lsp.diagnostic.get_prev()
  118. end
  119. function nv_utils.goto_next()
  120. vim.lsp.diagnostic.goto_next()
  121. end
  122. function nv_utils.goto_prev()
  123. vim.lsp.diagnostic.goto_prev()
  124. end
  125. function nv_utils.show_line_diagnostics()
  126. vim.lsp.diagnostic.show_line_diagnostics()
  127. end
  128. -- git signs
  129. function nv_utils.next_hunk()
  130. require('gitsigns').next_hunk()
  131. end
  132. function nv_utils.prev_hunk()
  133. require('gitsigns').prev_hunk()
  134. end
  135. function nv_utils.stage_hunk()
  136. require('gitsigns').stage_hunk()
  137. end
  138. function nv_utils.undo_stage_hunk()
  139. require('gitsigns').undo_stage_hunk()
  140. end
  141. function nv_utils.reset_hunk()
  142. require('gitsigns').reset_hunk()
  143. end
  144. function nv_utils.reset_buffer()
  145. require('gitsigns').reset_buffer()
  146. end
  147. function nv_utils.preview_hunk()
  148. require('gitsigns').preview_hunk()
  149. end
  150. function nv_utils.blame_line()
  151. require('gitsigns').blame_line()
  152. end
  153. -- misc
  154. function nv_utils.file_exists(name)
  155. local f=io.open(name,"r")
  156. if f~=nil then io.close(f) return true else return false end
  157. end
  158. -- autoformat
  159. -- autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 1000)
  160. return nv_utils