From 133dd683223dd07437a86c802c404446c33b82dd Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Wed, 20 Oct 2021 14:18:50 +0700 Subject: [PATCH] neovim: update multiple - nvim-ts-rainbow: move config into 'nvim-treesitter.configs' block - bufferline.nvim: update lsp diagnostic display, highlight - gitsigns.nvim: add highlight for line blame info - nvim-autopairs: update new config - highlight: no more lazy loading (only 1-2ms faster, and caused some glitched highlights at startup due to treesitter group) - chore: theme.util -> util --- home/.config/nvim/lua/modules/completion.lua | 36 +++++++++++++++++-- home/.config/nvim/lua/modules/editor.lua | 16 ++++----- home/.config/nvim/lua/modules/ui.lua | 22 ++++++++++-- home/.config/nvim/lua/plugins.lua | 7 +--- home/.config/nvim/lua/themes/init.lua | 16 +++------ home/.config/nvim/lua/themes/nord/init.lua | 23 ++---------- home/.config/nvim/lua/themes/onedark/init.lua | 2 +- home/.config/nvim/lua/{themes => }/util.lua | 0 8 files changed, 70 insertions(+), 52 deletions(-) rename home/.config/nvim/lua/{themes => }/util.lua (100%) diff --git a/home/.config/nvim/lua/modules/completion.lua b/home/.config/nvim/lua/modules/completion.lua index b44c3a1..66d6c26 100644 --- a/home/.config/nvim/lua/modules/completion.lua +++ b/home/.config/nvim/lua/modules/completion.lua @@ -144,11 +144,43 @@ end -- end function M.autopairs_conf() - require('nvim-autopairs').setup {fast_wrap = {}} + require('nvim-autopairs').setup { + disable_filetype = {'TelescopePrompt', 'spectre_panel'}, + disable_in_macro = false, -- disable when recording or executing a macro + ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]], '%s+', ''), + enable_moveright = true, + enable_afterquote = true, -- add bracket pairs after quote + enable_check_bracket_line = true, -- check bracket in same line + check_ts = true, -- use treesitter + ts_config = { + lua = {'string', 'source'}, + javascript = {'string', 'template_string'} + }, + map_bs = true, -- map the key + map_c_w = true, -- map to delete an pair if possible + map_cr = false, -- use mapping for nvim-cmp below instead + fast_wrap = { + map = '', + chars = { '{', '[', '(', '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], '%s+', ''), + offset = 0, -- Offset from pattern match + end_key = '$', + keys = 'qwertyuiopzxcvbnmasdfghjkl', + check_comma = true, + highlight = 'Search', + highlight_grey = 'Comment' + } + } + require('nvim-autopairs.completion.cmp').setup { map_cr = true, -- map on insert mode map_complete = true, -- it will auto insert `(` after select function or method item - auto_select = true -- automatically select the first item + auto_select = true, -- automatically select the first item + insert = false, -- use insert confirm behavior instead of replace + map_char = { -- modifies the function or method delimiter by filetypes + all = '(', + tex = '{' + } } end diff --git a/home/.config/nvim/lua/modules/editor.lua b/home/.config/nvim/lua/modules/editor.lua index 3473ea8..d0b5934 100644 --- a/home/.config/nvim/lua/modules/editor.lua +++ b/home/.config/nvim/lua/modules/editor.lua @@ -34,6 +34,7 @@ function M.blankline_conf() }, buftype_exclude = {'terminal', 'nofile'}, show_trailing_blankline_indent = false, + -- show_end_of_line = true, show_current_context = true, context_patterns = { 'class', 'function', 'method', 'block', 'list_literal', 'selector', '^if', @@ -108,6 +109,11 @@ function M.treesitter_conf() } }, matchup = {enable = true}, + rainbow = { + enable = true, + extended_mode = true, + max_file_lines = 1000 + }, playground = { enable = true, disable = {}, @@ -166,16 +172,6 @@ function M.iswap_conf() } end -function M.rainbow_conf() - require('nvim-treesitter.configs').setup { - rainbow = { - enable = true, - extended_mode = true, - max_file_lines = 1000 - } - } -end - function M.matchup_conf() vim.g.matchup_matchparen_offscreen = {method = 'popup'} end diff --git a/home/.config/nvim/lua/modules/ui.lua b/home/.config/nvim/lua/modules/ui.lua index 805e438..3511e97 100644 --- a/home/.config/nvim/lua/modules/ui.lua +++ b/home/.config/nvim/lua/modules/ui.lua @@ -326,6 +326,15 @@ function M.bufferline_conf() max_prefix_length = 14, tab_size = 20, diagnostics = 'nvim_lsp', + diagnostics_update_in_insert = false, + diagnostics_indicator = function(count, level, diagnostics_dict, context) + local s = ' ' + for e, n in pairs(diagnostics_dict) do + local sym = e == 'error' and 'x ' or (e == 'warning' and '! ' or (e == 'info' and 'i ' or '? ')) + s = s .. n .. sym + end + return s + end, show_close_icon = false, show_buffer_icons = true, show_tab_indicators = true, @@ -340,7 +349,14 @@ function M.bufferline_conf() }, highlights = { fill = {guibg = {attribute = 'bg', highlight = 'TabLineFill'}}, - indicator_selected = {guifg = {attribute = 'fg', highlight = 'TabLineSel'}} + indicator_selected = {guifg = {attribute = 'fg', highlight = 'TabLineSel'}}, + diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignHint', gui = 'bold,italic'}}, + info_diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignInformation', gui = 'bold,italic'}}, + info_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsDefaultInformation', gui = 'bold,italic'}}, + warning_diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignWarning', gui = 'bold,italic'}}, + warning_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsDefaultWarning', gui = 'bold,italic'}}, + error_diagnostic_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsSignError', gui = 'bold,italic'}}, + error_selected = {guifg = {attribute = 'fg', highlight = 'LspDiagnosticsDefaultError', gui = 'bold,italic'}} } } end @@ -477,11 +493,12 @@ function M.gitsigns_conf() interval = 1000, follow_files = true }, + attach_to_untracked = true, current_line_blame = false, current_line_blame_opts = { delay = 1000, virt_text = true, - virt_text_pos = 'eol' + virt_text_pos = 'right_align' }, current_line_blame_formatter_opts = { relative_time = false @@ -502,6 +519,7 @@ function M.gitsigns_conf() enable = false }, diff_opts = { + algorithm = 'myers', -- others: 'minimal', 'patience', 'histogram' internal = true -- If luajit is present } } diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index 48efac2..bf618ad 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -75,6 +75,7 @@ return packer.startup(function(use) event = 'BufRead', config = editor.treesitter_conf } + use {'p00f/nvim-ts-rainbow', after = 'nvim-treesitter'} use {'nvim-treesitter/playground', after = 'nvim-treesitter'} use {'romgrk/nvim-treesitter-context', after = 'nvim-treesitter'} use {'nvim-treesitter/nvim-treesitter-textobjects', after = 'nvim-treesitter'} @@ -83,12 +84,6 @@ return packer.startup(function(use) after = 'nvim-treesitter', config = editor.blankline_conf } - use { - 'p00f/nvim-ts-rainbow', - after = 'nvim-treesitter', - -- Putting config into `treesitter_conf` doesn't work for some reason - config = editor.rainbow_conf - } use { 'mizlan/iswap.nvim', cmd = {'ISwapWith', 'ISwap'}, diff --git a/home/.config/nvim/lua/themes/init.lua b/home/.config/nvim/lua/themes/init.lua index 2fc0ea2..dcc025d 100644 --- a/home/.config/nvim/lua/themes/init.lua +++ b/home/.config/nvim/lua/themes/init.lua @@ -11,19 +11,13 @@ function M.set(theme) vim.g.colors_name = theme -- Load highlight groups - local async - async = vim.loop.new_async(vim.schedule_wrap(function() - t.set_vim_termcolors() - t.highlight_plugins() - t.highlight_languages() - t.highlight_treesitter() - t.highlight_lsp() - async:close() - end)) - t.highlight_editor() t.highlight_syntax() - async:send() -- Load the rest later + t.set_vim_termcolors() + t.highlight_plugins() + t.highlight_languages() + t.highlight_treesitter() + t.highlight_lsp() end return M diff --git a/home/.config/nvim/lua/themes/nord/init.lua b/home/.config/nvim/lua/themes/nord/init.lua index 70eb14f..447162e 100644 --- a/home/.config/nvim/lua/themes/nord/init.lua +++ b/home/.config/nvim/lua/themes/nord/init.lua @@ -2,7 +2,7 @@ local cmd = vim.api.nvim_command local M = {} local c = require('themes.nord.colors') -local hi = require('themes.util').highlight +local hi = require('util').highlight -- Set terminal colors function M.set_vim_termcolors() @@ -286,24 +286,6 @@ function M.highlight_lsp() hi('LspReferenceRead', c.fg, c.grey_bright, '', '') hi('LspReferenceWrite', c.fg, c.grey_bright, '', '') cmd('hi! link LspCodeLens Comment') - - -- Theses are for neovim 0.6 - -- cmd('hi! link DiagnosticVirtualTextWarn LspDiagnosticsVirtualTextWarning') - -- cmd('hi! link DiagnosticUnderlineWarn LspDiagnosticsUnderlineWarning') - -- cmd('hi! link DiagnosticFloatingWarn LspDiagnosticsFloatingWarning') - -- cmd('hi! link DiagnosticSignWarn LspDiagnosticsSignWarning') - -- cmd('hi! link DiagnosticVirtualTextError LspDiagnosticsVirtualTextError') - -- cmd('hi! link DiagnosticUnderlineError LspDiagnosticsUnderlineError') - -- cmd('hi! link DiagnosticFloatingError LspDiagnosticsFloatingError') - -- cmd('hi! link DiagnosticSignError LspDiagnosticsSignError') - -- cmd('hi! link DiagnosticVirtualTextInfo LspDiagnosticsVirtualTextInformation') - -- cmd('hi! link DiagnosticUnderlineInfo LspDiagnosticsUnderlineInformation') - -- cmd('hi! link DiagnosticFloatingInfo LspDiagnosticsFloatingInformation') - -- cmd('hi! link DiagnosticSignInfo LspDiagnosticsSignInformation') - -- cmd('hi! link DiagnosticVirtualTextHint LspDiagnosticsVirtualTextHint') - -- cmd('hi! link DiagnosticUnderlineHint LspDiagnosticsUnderlineHint') - -- cmd('hi! link DiagnosticFloatingHint LspDiagnosticsFloatingHint') - -- cmd('hi! link DiagnosticSignHint LspDiagnosticsSignHint') end -- Specify groups for plugins @@ -319,6 +301,7 @@ function M.highlight_plugins() hi('GitSignsAddNr' , c.green , '', '', '') hi('GitSignsChangeNr', c.yellow, '', '', '') hi('GitSignsDeleteNr', c.red , '', '', '') + hi('GitSignsCurrentLineBlame', c.grey_bright, '', 'italic,bold', '') -- ts-rainbow hi('rainbowcol1', c.red, '', 'bold', '') @@ -371,7 +354,7 @@ function M.highlight_plugins() -- Indent Blankline hi('IndentBlanklineChar', c.grey1, '', '', '') - hi('IndentBlanklineContextChar', c.grey1, '', '', '') + hi('IndentBlanklineContextChar', c.grey_bright, '', '', '') -- window-picker.nvim hi('WindowPicker', c.fg, c.blue, 'bold', '') diff --git a/home/.config/nvim/lua/themes/onedark/init.lua b/home/.config/nvim/lua/themes/onedark/init.lua index b1f34ab..3b7a6f6 100644 --- a/home/.config/nvim/lua/themes/onedark/init.lua +++ b/home/.config/nvim/lua/themes/onedark/init.lua @@ -1,7 +1,7 @@ local M = {} local c = require('themes.onedark.colors') -local hi = require('themes.util').highlight +local hi = require('util').highlight function M.highlight_editor() hi('ModeMsg', c.fg, '', '', '') diff --git a/home/.config/nvim/lua/themes/util.lua b/home/.config/nvim/lua/util.lua similarity index 100% rename from home/.config/nvim/lua/themes/util.lua rename to home/.config/nvim/lua/util.lua