From 2498e73c10f8ac228efc063923a1e2914bd698e9 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Mon, 14 Feb 2022 17:20:33 +0100 Subject: [PATCH] vim: move custom highlights to colorscheme config() --- .../nvim/lua/fs/config/indent-blankline.lua | 12 ++---- config/nvim/lua/fs/config/nvim-tree.lua | 14 +------ .../lua/fs/config/vim-better-whitespace.lua | 7 +--- .../lua/fs/config/vim-colors-solarized.lua | 38 ++++++++++++++++--- config/nvim/lua/fs/config/virt-column.lua | 10 ++--- config/nvim/lua/fs/util.lua | 21 +++++----- 6 files changed, 50 insertions(+), 52 deletions(-) diff --git a/config/nvim/lua/fs/config/indent-blankline.lua b/config/nvim/lua/fs/config/indent-blankline.lua index becf472..025ceb5 100644 --- a/config/nvim/lua/fs/config/indent-blankline.lua +++ b/config/nvim/lua/fs/config/indent-blankline.lua @@ -1,15 +1,9 @@ -local util = require'fs.util' -local nmap = util.nmap -local colors = util.colors() -local highlight = util.highlight +local nmap = require'fs.util'.nmap local config = function() - vim.g.indent_blankline_enabled = false - - require'indent_blankline'.setup() - - highlight('IndentBlanklineChar') { fg = colors.base01 } + require'indent_blankline'.setup { enabled = false } + -- show/hide indent guides nmap { 'si', ':IndentBlanklineToggle' } end diff --git a/config/nvim/lua/fs/config/nvim-tree.lua b/config/nvim/lua/fs/config/nvim-tree.lua index dbbd408..cdeddfe 100644 --- a/config/nvim/lua/fs/config/nvim-tree.lua +++ b/config/nvim/lua/fs/config/nvim-tree.lua @@ -1,7 +1,4 @@ -local util = require'fs.util' -local nmap = util.nmap -local colors = util.colors() -local highlight = util.highlight +local nmap = require'fs.util'.nmap -- helper to set vim.g options that will be moved to setup() later local function set_globals(tbl) @@ -41,15 +38,6 @@ local config = function() }, } - highlight('NvimTreeSpecialFile') { fg = colors.base2 } - highlight('NvimTreeIndentMarker') { fg = colors.base01 } - highlight('NvimTreeGitStaged') { fg = colors.green } - highlight('NvimTreeGitRenamed') { fg = colors.yellow } - highlight('NvimTreeGitNew') { fg = colors.yellow } - highlight('NvimTreeGitDirty') { fg = colors.yellow } - highlight('NvimTreeGitDeleted') { fg = colors.orange } - highlight('NvimTreeGitMerge') { fg = colors.red } - nmap { '', 'NvimTreeToggle' } nmap { 'n', 'NvimTreeFindFileToggle' } end diff --git a/config/nvim/lua/fs/config/vim-better-whitespace.lua b/config/nvim/lua/fs/config/vim-better-whitespace.lua index 8ce70ae..b764b94 100644 --- a/config/nvim/lua/fs/config/vim-better-whitespace.lua +++ b/config/nvim/lua/fs/config/vim-better-whitespace.lua @@ -1,7 +1,4 @@ -local util = require'fs.util' -local nmap = util.nmap -local colors = util.colors() -local highlight = util.highlight +local nmap = require'fs.util'.nmap local setup = function() vim.g.better_whitespace_filetypes_blacklist = { @@ -10,8 +7,6 @@ local setup = function() end local config = function() - highlight('ExtraWhitespace') { fg = colors.orange, bg = colors.orange } - -- fix whitespace nmap { 'w', 'StripWhitespace' } diff --git a/config/nvim/lua/fs/config/vim-colors-solarized.lua b/config/nvim/lua/fs/config/vim-colors-solarized.lua index 97a4336..0ae772f 100644 --- a/config/nvim/lua/fs/config/vim-colors-solarized.lua +++ b/config/nvim/lua/fs/config/vim-colors-solarized.lua @@ -2,15 +2,41 @@ local util = require'fs.util' local C = util.colors() local highlight = util.highlight +local additional_highlights = { + -- Override the colorscheme for these ones: + Normal = { bg = 'NONE' }, -- transparent background + NonText = { fg = C.base02, attrs = 'NONE' }, -- very subtle EOL symbols + Whitespace = { fg = C.orange }, -- listchars + SpellBad = { fg = C.yellow }, -- spelling mistakes + QuickFixLine = { fg = C.yellow, bg = C.base02 }, -- selected quickfix item + CursorLineNr = { fg = C.yellow, attrs = 'NONE' }, -- current line number + + -- Trailing whitespace, from 'ntpeters/vim-better-whitespace': + ExtraWhitespace = { fg = C.orange, bg = C.orange }, + + -- Indentation guids, from 'lukas-reineke/indent-blankline.nvim': + IndentBlanklineChar = { fg = C.base01 }, + + -- Virtual colorcolumn, from 'lukas-reineke/virt-column.nvim': + VirtColumn = { fg = C.base02, bg = C.base03, attrs = 'NONE' }, + + -- Colors for 'kyazdani42/nvim-tree.lua': + NvimTreeSpecialFile = { fg = C.base2 }, + NvimTreeIndentMarker = { fg = C.base01 }, + NvimTreeGitStaged = { fg = C.green }, + NvimTreeGitRenamed = { fg = C.yellow }, + NvimTreeGitNew = { fg = C.yellow }, + NvimTreeGitDirty = { fg = C.yellow }, + NvimTreeGitDeleted = { fg = C.orange }, + NvimTreeGitMerge = { fg = C.red }, +} + local config = function() vim.cmd [[silent! colorscheme solarized]] - highlight('Normal') { bg = 'NONE' } -- transparent background - highlight('NonText') { fg = C.base02, attrs = 'NONE' } -- subtle EOL symbols - highlight('Whitespace') { fg = C.orange } -- listchars - highlight('SpellBad') { fg = C.yellow } - highlight('QuickFixLine') { fg = C.yellow, bg = C.base02 } -- selected quickfix item - highlight('CursorLineNr') { fg = C.yellow, attrs = 'NONE' } -- current line number + for group, hl in pairs(additional_highlights) do + highlight(group, hl) + end end return { config = config } diff --git a/config/nvim/lua/fs/config/virt-column.lua b/config/nvim/lua/fs/config/virt-column.lua index f3210b5..8d47992 100644 --- a/config/nvim/lua/fs/config/virt-column.lua +++ b/config/nvim/lua/fs/config/virt-column.lua @@ -1,7 +1,4 @@ -local util = require'fs.util' -local nmap = util.nmap -local colors = util.colors() -local highlight = util.highlight +local nmap = require'fs.util'.nmap local toggle = function() if vim.o.colorcolumn == '' then @@ -14,9 +11,8 @@ end local config = function() require'virt-column'.setup { char = '│' } - highlight('VirtColumn') { fg = colors.base02, attrs = 'NONE' } - - nmap { 'sc', 'lua require"fs.config.virt-column".toggle()' } + -- show/hide virtual colorcolumn + nmap { 'sc', [[lua require'fs.config.virt-column'.toggle()]] } end return { config = config, toggle = toggle } diff --git a/config/nvim/lua/fs/util.lua b/config/nvim/lua/fs/util.lua index f015ee2..f6e6915 100644 --- a/config/nvim/lua/fs/util.lua +++ b/config/nvim/lua/fs/util.lua @@ -58,19 +58,18 @@ M.colors = function(gui) end -- Usage example: --- highlight('Test2') { fg = C.yellow, bg = C.base02 } -M.highlight = function(name) - return function(tbl) - local kind = vim.opt.termguicolors:get() and 'gui' or 'cterm' +-- highlight('Test2', { fg = C.yellow, bg = C.base02 }) +M.highlight = function(group, highlights) + local kind = vim.opt.termguicolors:get() and 'gui' or 'cterm' - local parts = {} - for k, v in pairs(tbl) do - if k == 'attrs' then k = '' end - table.insert(parts, kind .. k .. '=' .. v) - end - - vim.cmd('highlight ' .. name .. ' ' .. vim.fn.join(parts, ' ')) + local parts = {} + for k, v in pairs(highlights) do + if k == 'attrs' then k = '' end + table.insert(parts, kind .. k .. '=' .. v) end + + local cmd = 'highlight ' .. group .. ' ' .. vim.fn.join(parts, ' ') + vim.cmd(cmd) end return M