init.lua 5.7 KB

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