init.lua 5.1 KB

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