init.lua 5.2 KB

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