init.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. -- TODO when autocommands are better in lua, scope these to plugins and langs
  2. local utils = require('lv-utils')
  3. local auto_formatters = {}
  4. if O.lang.python.active then
  5. local python_autoformat = {
  6. 'BufWritePre', '*.py', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'
  7. }
  8. if O.lang.python.autoformat then
  9. table.insert(auto_formatters, python_autoformat)
  10. end
  11. end
  12. if O.lang.tsserver.active then
  13. local javascript_autoformat = {
  14. 'BufWritePre', '*.js', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'
  15. }
  16. local javascriptreact_autoformat = {
  17. 'BufWritePre', '*.jsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'
  18. }
  19. local typescript_autoformat = {
  20. 'BufWritePre', '*.ts', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'
  21. }
  22. local typescriptreact_autoformat = {
  23. 'BufWritePre', '*.tsx', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'
  24. }
  25. if O.lang.tsserver.autoformat then
  26. table.insert(auto_formatters, javascript_autoformat)
  27. table.insert(auto_formatters, javascriptreact_autoformat)
  28. table.insert(auto_formatters, typescript_autoformat)
  29. table.insert(auto_formatters, typescriptreact_autoformat)
  30. end
  31. end
  32. if O.lang.lua.active then
  33. local lua_format = {
  34. 'BufWritePre', '*.lua', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'
  35. }
  36. if O.lang.lua.autoformat then table.insert(auto_formatters, lua_format) end
  37. end
  38. if O.lang.json.active then
  39. local json_format = {
  40. 'BufWritePre', '*.json', 'lua vim.lsp.buf.formatting_sync(nil, 1000)'
  41. }
  42. if O.lang.json.autoformat then table.insert(auto_formatters, json_format) end
  43. end
  44. if O.lang.ruby.active then
  45. local ruby_format = {
  46. 'BufWritePre', '*.rb', 'lua vim.lsp.buf.formatting_sync(nil,1000)'
  47. }
  48. if O.lang.ruby.autoformat then table.insert(auto_formatters, ruby_format) end
  49. end
  50. if O.lang.go.active then
  51. local go_format = {
  52. 'BufWritePre', '*.go', 'lua vim.lsp.buf.formatting_sync(nil,1000)'
  53. }
  54. if O.lang.go.autoformat then table.insert(auto_formatters, go_format) end
  55. end
  56. if O.lang.rust.active then
  57. local rust_format = {
  58. 'BufWritePre', '*.rs', 'lua vim.lsp.buf.formatting_sync(nil,1000)'
  59. }
  60. if O.lang.rust.autoformat then table.insert(auto_formatters, rust_format) end
  61. end
  62. utils.define_augroups({
  63. _general_settings = {
  64. {
  65. 'TextYankPost', '*',
  66. 'lua require(\'vim.highlight\').on_yank({higroup = \'Search\', timeout = 200})'
  67. }, {
  68. 'BufWinEnter', '*',
  69. 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'
  70. },
  71. {
  72. 'BufRead', '*',
  73. 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'
  74. }, {
  75. 'BufNewFile', '*',
  76. 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'
  77. }, {'VimLeavePre', '*', 'set title set titleold='},
  78. {'FileType', 'qf', 'set nobuflisted'},
  79. -- {'BufWinEnter', 'lv-config.lua', 'PackerCompile'},
  80. -- {'BufWinLeave', 'lv-config.lua', 'PackerCompile'},
  81. -- {'BufWritePost', 'lv-config.lua', 'PackerCompile'}
  82. -- {'User', 'GoyoLeave', 'lua require(\'galaxyline\').disable_galaxyline()'},
  83. -- {'User', 'GoyoEnter', 'lua require(\'galaxyline\').galaxyline_augroup()'},
  84. },
  85. _java = {
  86. -- {'FileType', 'java', 'luafile '..CONFIG_PATH..'/lua/lsp/java-ls.lua'},
  87. {
  88. 'FileType', 'java',
  89. 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'
  90. }
  91. },
  92. _go = {
  93. -- Go generally requires Tabs instead of spaces.
  94. {'FileType', 'go', 'setlocal tabstop=4'},
  95. {'FileType', 'go', 'setlocal shiftwidth=4'},
  96. {'FileType', 'go', 'setlocal softtabstop=4'},
  97. {'FileType', 'go', 'setlocal noexpandtab'}
  98. },
  99. _dashboard = {
  100. -- seems to be nobuflisted that makes my stuff disapear will do more testing
  101. {
  102. 'FileType', 'dashboard',
  103. 'setlocal nocursorline noswapfile synmaxcol& signcolumn=no norelativenumber nocursorcolumn nospell nolist nonumber bufhidden=wipe colorcolumn= foldcolumn=0 matchpairs= '
  104. }, {
  105. 'FileType', 'dashboard',
  106. 'set showtabline=0 | autocmd BufLeave <buffer> set showtabline=2'
  107. }
  108. },
  109. _markdown = {
  110. {'FileType', 'markdown', 'setlocal wrap'},
  111. {'FileType', 'markdown', 'setlocal spell'}
  112. },
  113. -- _solidity = {
  114. -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'},
  115. -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'}
  116. -- },
  117. -- _gemini = {
  118. -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'},
  119. -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'}
  120. -- },
  121. _buffer_bindings = {
  122. {'FileType', 'dashboard', 'nnoremap <silent> <buffer> q :q<CR>'},
  123. {'FileType', 'lspinfo', 'nnoremap <silent> <buffer> q :q<CR>'},
  124. {'FileType', 'floaterm', 'nnoremap <silent> <buffer> q :q<CR>'}
  125. },
  126. _auto_formatters = auto_formatters
  127. })