comparison .chezmoitemplates/init.lua @ 600:24b0dd06381b

Enable collapsed statements for stylua
author Zeger Van de Vannet <zegervdv@me.com>
date Fri, 08 Jul 2022 16:46:27 +0200
parents 1def7efdc619
children 837e6ed64a90
comparison
equal deleted inserted replaced
599:1def7efdc619 600:24b0dd06381b
4 -- 4 --
5 local execute = vim.api.nvim_command 5 local execute = vim.api.nvim_command
6 local fn = vim.fn 6 local fn = vim.fn
7 7
8 local home = os.getenv 'HOME' 8 local home = os.getenv 'HOME'
9 if home == nil then 9 if home == nil then home = os.getenv 'USERPROFILE' end
10 home = os.getenv 'USERPROFILE'
11 end
12 10
13 -- Bootstrap package manager 11 -- Bootstrap package manager
14 local install_path = fn.stdpath 'data' .. '/site/pack/packer/opt/packer.nvim' 12 local install_path = fn.stdpath 'data' .. '/site/pack/packer/opt/packer.nvim'
15 13
16 if fn.empty(fn.glob(install_path)) > 0 then 14 if fn.empty(fn.glob(install_path)) > 0 then
51 } 49 }
52 50
53 -- Smooth scrolling 51 -- Smooth scrolling
54 use { 52 use {
55 'karb94/neoscroll.nvim', 53 'karb94/neoscroll.nvim',
56 config = function() 54 config = function() require('neoscroll').setup {} end,
57 require('neoscroll').setup {}
58 end,
59 } 55 }
60 56
61 -- Faster lua package loading (until 15436 is merged) 57 -- Faster lua package loading (until 15436 is merged)
62 use { 58 use {
63 'lewis6991/impatient.nvim', 59 'lewis6991/impatient.nvim',
64 module = { 'impatient' }, 60 module = { 'impatient' },
65 setup = function() 61 setup = function() require 'impatient' end,
66 require 'impatient'
67 end,
68 } 62 }
69 63
70 -- Library with lua functions 64 -- Library with lua functions
71 use { 'nvim-lua/plenary.nvim' } 65 use { 'nvim-lua/plenary.nvim' }
72 66
156 Rule(' ', ' '):with_pair(function(opts) 150 Rule(' ', ' '):with_pair(function(opts)
157 local pair = opts.line:sub(opts.col - 1, opts.col) 151 local pair = opts.line:sub(opts.col - 1, opts.col)
158 return vim.tbl_contains({ '()', '[]', '{}' }, pair) 152 return vim.tbl_contains({ '()', '[]', '{}' }, pair)
159 end), 153 end),
160 Rule('( ', ' )') 154 Rule('( ', ' )')
161 :with_pair(function() 155 :with_pair(function() return false end)
162 return false 156 :with_move(function(opts) return opts.prev_char:match '.%)' ~= nil end)
163 end)
164 :with_move(function(opts)
165 return opts.prev_char:match '.%)' ~= nil
166 end)
167 :use_key ')', 157 :use_key ')',
168 Rule('{ ', ' }') 158 Rule('{ ', ' }')
169 :with_pair(function() 159 :with_pair(function() return false end)
170 return false 160 :with_move(function(opts) return opts.prev_char:match '.%}' ~= nil end)
171 end)
172 :with_move(function(opts)
173 return opts.prev_char:match '.%}' ~= nil
174 end)
175 :use_key '}', 161 :use_key '}',
176 Rule('[ ', ' ]') 162 Rule('[ ', ' ]')
177 :with_pair(function() 163 :with_pair(function() return false end)
178 return false 164 :with_move(function(opts) return opts.prev_char:match '.%]' ~= nil end)
179 end)
180 :with_move(function(opts)
181 return opts.prev_char:match '.%]' ~= nil
182 end)
183 :use_key ']', 165 :use_key ']',
184 } 166 }
185 167
186 npairs.get_rule('`'):with_pair(function() 168 npairs.get_rule('`'):with_pair(function() return vim.bo.filetype ~= 'systemverilog' end)
187 return vim.bo.filetype ~= 'systemverilog' 169
188 end) 170 npairs.get_rule("'")[1]:with_pair(function() return vim.bo.filetype ~= 'systemverilog' end)
189
190 npairs.get_rule("'")[1]:with_pair(function()
191 return vim.bo.filetype ~= 'systemverilog'
192 end)
193 end, 171 end,
194 after = { 'nvim-cmp' }, 172 after = { 'nvim-cmp' },
195 } 173 }
196 174
197 -- Moving around within lines 175 -- Moving around within lines
226 -- session management 204 -- session management
227 use { 205 use {
228 'folke/persistence.nvim', 206 'folke/persistence.nvim',
229 event = 'BufReadPre', 207 event = 'BufReadPre',
230 module = 'persistence', 208 module = 'persistence',
231 config = function() 209 config = function() require('persistence').setup() end,
232 require('persistence').setup()
233 end,
234 } 210 }
235 211
236 -- Indent lines 212 -- Indent lines
237 use { 213 use {
238 'lukas-reineke/indent-blankline.nvim', 214 'lukas-reineke/indent-blankline.nvim',
262 use { 238 use {
263 'numtostr/navigator.nvim', 239 'numtostr/navigator.nvim',
264 config = function() 240 config = function()
265 require('Navigator').setup { auto_save = 'current', disable_on_zoom = true } 241 require('Navigator').setup { auto_save = 'current', disable_on_zoom = true }
266 242
267 local nmap = function(lhs, rhs, opts) 243 local nmap = function(lhs, rhs, opts) return vim.keymap.set('n', lhs, rhs, opts) end
268 return vim.keymap.set('n', lhs, rhs, opts)
269 end
270 nmap('<c-h>', require('Navigator').left, { silent = true }) 244 nmap('<c-h>', require('Navigator').left, { silent = true })
271 nmap('<c-j>', require('Navigator').down, { silent = true }) 245 nmap('<c-j>', require('Navigator').down, { silent = true })
272 nmap('<c-k>', require('Navigator').up, { silent = true }) 246 nmap('<c-k>', require('Navigator').up, { silent = true })
273 nmap('<c-l>', require('Navigator').right, { silent = true }) 247 nmap('<c-l>', require('Navigator').right, { silent = true })
274 end, 248 end,
295 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil 269 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil
296 end 270 end
297 271
298 cmp.setup { 272 cmp.setup {
299 snippet = { 273 snippet = {
300 expand = function(args) 274 expand = function(args) luasnip.lsp_expand(args.body) end,
301 luasnip.lsp_expand(args.body)
302 end,
303 }, 275 },
304 mapping = { 276 mapping = {
305 ['<C-p>'] = { i = cmp.mapping.select_prev_item() }, 277 ['<C-p>'] = { i = cmp.mapping.select_prev_item() },
306 ['<C-n>'] = { i = cmp.mapping.select_next_item() }, 278 ['<C-n>'] = { i = cmp.mapping.select_next_item() },
307 ['<C-d>'] = { i = cmp.mapping.scroll_docs(-4) }, 279 ['<C-d>'] = { i = cmp.mapping.scroll_docs(-4) },
408 { 'nvim-treesitter/playground', opt = true }, 380 { 'nvim-treesitter/playground', opt = true },
409 } 381 }
410 use { 'L3MON4D3/luasnip' } 382 use { 'L3MON4D3/luasnip' }
411 use { 383 use {
412 'rmagatti/goto-preview', 384 'rmagatti/goto-preview',
413 config = function() 385 config = function() require('goto-preview').setup {} end,
414 require('goto-preview').setup {}
415 end,
416 } 386 }
417 use { 387 use {
418 'jose-elias-alvarez/null-ls.nvim', 388 'jose-elias-alvarez/null-ls.nvim',
419 requires = 'nvim-lua/plenary.nvim', 389 requires = 'nvim-lua/plenary.nvim',
420 } 390 }
421 use { 391 use {
422 'lukas-reineke/lsp-format.nvim', 392 'lukas-reineke/lsp-format.nvim',
423 config = function() 393 config = function() require('lsp-format').setup {} end,
424 require('lsp-format').setup {}
425 end,
426 } 394 }
427 use { 'folke/lua-dev.nvim' } 395 use { 'folke/lua-dev.nvim' }
428 use { 396 use {
429 'folke/trouble.nvim', 397 'folke/trouble.nvim',
430 config = function() 398 config = function()
457 425
458 colors.bg = '#2C323C' 426 colors.bg = '#2C323C'
459 427
460 gls.left[1] = { 428 gls.left[1] = {
461 RainbowRed = { 429 RainbowRed = {
462 provider = function() 430 provider = function() return '▊ ' end,
463 return '▊ '
464 end,
465 highlight = { colors.blue, colors.bg }, 431 highlight = { colors.blue, colors.bg },
466 }, 432 },
467 } 433 }
468 434
469 gls.left[2] = { 435 gls.left[2] = {
470 FileName = { 436 FileName = {
471 provider = function() 437 provider = function() return require('galaxyline.providers.fileinfo').get_current_file_name '⊙' end,
472 return require('galaxyline.providers.fileinfo').get_current_file_name '⊙'
473 end,
474 condition = condition.buffer_not_empty, 438 condition = condition.buffer_not_empty,
475 highlight = { colors.magenta, colors.bg, 'bold' }, 439 highlight = { colors.magenta, colors.bg, 'bold' },
476 }, 440 },
477 } 441 }
478 442
479 gls.right[1] = { 443 gls.right[1] = {
480 ShowLspClient = { 444 ShowLspClient = {
481 provider = 'GetLspClient', 445 provider = 'GetLspClient',
482 condition = function() 446 condition = function()
483 local tbl = { ['dashboard'] = true, [''] = true } 447 local tbl = { ['dashboard'] = true, [''] = true }
484 if tbl[vim.bo.filetype] then 448 if tbl[vim.bo.filetype] then return false end
485 return false
486 end
487 return true 449 return true
488 end, 450 end,
489 highlight = { colors.green, colors.bg, 'bold' }, 451 highlight = { colors.green, colors.bg, 'bold' },
490 }, 452 },
491 } 453 }
507 highlight = { colors.fg, colors.bg, 'bold' }, 469 highlight = { colors.fg, colors.bg, 'bold' },
508 }, 470 },
509 } 471 }
510 gls.right[8] = { 472 gls.right[8] = {
511 RainbowBlue = { 473 RainbowBlue = {
512 provider = function() 474 provider = function() return ' ▊' end,
513 return ' ▊'
514 end,
515 highlight = { colors.blue, colors.bg }, 475 highlight = { colors.blue, colors.bg },
516 }, 476 },
517 } 477 }
518 478
519 gls.short_line_left[1] = { 479 gls.short_line_left[1] = {
591 use { 'lepture/vim-jinja' } 551 use { 'lepture/vim-jinja' }
592 552
593 -- Integration with external tools 553 -- Integration with external tools
594 use { 554 use {
595 'glacambre/firenvim', 555 'glacambre/firenvim',
596 run = function() 556 run = function() vim.fn['firenvim#install'](0) end,
597 vim.fn['firenvim#install'](0)
598 end,
599 config = function() 557 config = function()
600 vim.g.firenvim_config = { 558 vim.g.firenvim_config = {
601 localSettings = { 559 localSettings = {
602 ['.*'] = { 560 ['.*'] = {
603 takeover = 'never', 561 takeover = 'never',
748 opt.foldtext = 706 opt.foldtext =
749 [[substitute(getline(v:foldstart),'\\t',repeat('\ ',&tabstop),'g').'...'.trim(getline(v:foldend)) . ' (' . (v:foldend - v:foldstart + 1) . ' lines)']] 707 [[substitute(getline(v:foldstart),'\\t',repeat('\ ',&tabstop),'g').'...'.trim(getline(v:foldend)) . ' (' . (v:foldend - v:foldstart + 1) . ' lines)']]
750 opt.foldenable = false 708 opt.foldenable = false
751 709
752 -- Clean up terminal codes from strings 710 -- Clean up terminal codes from strings
753 local t = function(str) 711 local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end
754 return vim.api.nvim_replace_termcodes(str, true, true, true)
755 end
756 712
757 -- General keymaps 713 -- General keymaps
758 local map = vim.keymap.set 714 local map = vim.keymap.set
759 715
760 -- Set leader to space 716 -- Set leader to space
821 map('n', '<RIGHT>', ':cnf<CR>', { desc = 'Go to next error/match in next file' }) 777 map('n', '<RIGHT>', ':cnf<CR>', { desc = 'Go to next error/match in next file' })
822 778
823 local au = require 'au' 779 local au = require 'au'
824 780
825 -- Highlight yanked text 781 -- Highlight yanked text
826 au.TextYankPost = function() 782 au.TextYankPost = function() vim.highlight.on_yank { timeout = 120 } end
827 vim.highlight.on_yank { timeout = 120 }
828 end
829 783
830 -- Automatic cursorline 784 -- Automatic cursorline
831 au.group('cline', { 785 au.group('cline', {
832 { 786 {
833 'WinEnter', 787 'WinEnter',
834 '*', 788 '*',
835 function() 789 function() vim.opt_local.cursorline = true end,
836 vim.opt_local.cursorline = true
837 end,
838 }, 790 },
839 { 791 {
840 'WinLeave', 792 'WinLeave',
841 '*', 793 '*',
842 function() 794 function() vim.opt_local.cursorline = false end,
843 vim.opt_local.cursorline = false
844 end,
845 }, 795 },
846 }) 796 })
847 797
848 -- Save files on focus lost 798 -- Save files on focus lost
849 au.FocusLost = function() 799 au.FocusLost = function()
850 if not vim.o.readonly and vim.api.nvim_buf_get_name(0) ~= '' then 800 if not vim.o.readonly and vim.api.nvim_buf_get_name(0) ~= '' then vim.cmd [[ wa ]] end
851 vim.cmd [[ wa ]]
852 end
853 end 801 end
854 802
855 -- Equalize splits after resizing 803 -- Equalize splits after resizing
856 au.VimResized = [[ exe "normal! \<c-w>=" ]] 804 au.VimResized = [[ exe "normal! \<c-w>=" ]]
857 805
858 -- Reload diffs after editing 806 -- Reload diffs after editing
859 au.BufWritePost = function() 807 au.BufWritePost = function()
860 if vim.o.diff then 808 if vim.o.diff then vim.cmd [[ diffupdate ]] end
861 vim.cmd [[ diffupdate ]]
862 end
863 end 809 end
864 810
865 -- Snippets 811 -- Snippets
866 local ls = require 'luasnip' 812 local ls = require 'luasnip'
867 -- Expand snippet or jump to next placeholder 813 -- Expand snippet or jump to next placeholder
868 vim.keymap.set({ 'i', 's' }, '<c-k>', function() 814 vim.keymap.set({ 'i', 's' }, '<c-k>', function()
869 if ls.expand_or_jumpable() then 815 if ls.expand_or_jumpable() then ls.expand_or_jump() end
870 ls.expand_or_jump()
871 end
872 end, { 816 end, {
873 silent = true, 817 silent = true,
874 }) 818 })
875 819
876 -- Go back to previous placeholder 820 -- Go back to previous placeholder
877 vim.keymap.set({ 'i', 's' }, '<c-j>', function() 821 vim.keymap.set({ 'i', 's' }, '<c-j>', function()
878 if ls.jumpable(-1) then 822 if ls.jumpable(-1) then ls.jump(-1) end
879 ls.jump(-1)
880 end
881 end, { 823 end, {
882 silent = true, 824 silent = true,
883 }) 825 })
884 826
885 -- Toggle options in snippets 827 -- Toggle options in snippets
886 vim.keymap.set('i', '<c-l>', function() 828 vim.keymap.set('i', '<c-l>', function()
887 if ls.choice_active() then 829 if ls.choice_active() then ls.change_choice() end
888 ls.change_choice()
889 end
890 end) 830 end)
891 831
892 -- LSP config 832 -- LSP config
893 local lsp = require 'lspconfig' 833 local lsp = require 'lspconfig'
894 local null_ls = require 'null-ls' 834 local null_ls = require 'null-ls'
895 835
896 local on_attach = function(client) 836 local on_attach = function(client)
897 require('lsp-format').on_attach(client) 837 require('lsp-format').on_attach(client)
898 local nmap = function(lhs, rhs, opts) 838 local nmap = function(lhs, rhs, opts) return vim.keymap.set('n', lhs, rhs, opts) end
899 return vim.keymap.set('n', lhs, rhs, opts)
900 end
901 839
902 vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc' 840 vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
903 nmap('gp', require('goto-preview').goto_preview_definition, { silent = true, buffer = 0 }) 841 nmap('gp', require('goto-preview').goto_preview_definition, { silent = true, buffer = 0 })
904 nmap('gP', require('goto-preview').close_all_win, { silent = true, buffer = 0 }) 842 nmap('gP', require('goto-preview').close_all_win, { silent = true, buffer = 0 })
905 843
908 nmap('gD', vim.lsp.buf.implementation, { silent = true, buffer = 0 }) 846 nmap('gD', vim.lsp.buf.implementation, { silent = true, buffer = 0 })
909 nmap('1gD', vim.lsp.buf.type_definition, { silent = true, buffer = 0 }) 847 nmap('1gD', vim.lsp.buf.type_definition, { silent = true, buffer = 0 })
910 nmap('gr', vim.lsp.buf.references, { silent = true, buffer = 0 }) 848 nmap('gr', vim.lsp.buf.references, { silent = true, buffer = 0 })
911 nmap('g0', vim.lsp.buf.document_symbol, { silent = true, buffer = 0 }) 849 nmap('g0', vim.lsp.buf.document_symbol, { silent = true, buffer = 0 })
912 850
913 nmap('<c-p>', function() 851 nmap('<c-p>', function() require('lsp-format').format() end, {
914 require('lsp-format').format()
915 end, {
916 silent = true, 852 silent = true,
917 buffer = 0, 853 buffer = 0,
918 }) 854 })
919 855
920 vim.bo.formatexpr = 'v:lua.vim.lsp.formatexpr()' 856 vim.bo.formatexpr = 'v:lua.vim.lsp.formatexpr()'
1040 }) 976 })
1041 vim.fn.sign_define('DiagnosticSignHint', { texthl = 'DiagnosticSignHint', linehl = '', numhl = '', text = '▎' }) 977 vim.fn.sign_define('DiagnosticSignHint', { texthl = 'DiagnosticSignHint', linehl = '', numhl = '', text = '▎' })
1042 978
1043 -- Try importing local config 979 -- Try importing local config
1044 local ok, localconfig = pcall(require, 'localconfig') 980 local ok, localconfig = pcall(require, 'localconfig')
1045 if ok then 981 if ok then localconfig.setup { on_attach = on_attach, capabilities = capabilities } end
1046 localconfig.setup { on_attach = on_attach, capabilities = capabilities }
1047 end