init.lua 5.4 KB

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