vim: move custom highlights to colorscheme config()

This commit is contained in:
Fernando Schauenburg 2022-02-14 17:20:33 +01:00
parent afdda2d4f3
commit 2498e73c10
6 changed files with 50 additions and 52 deletions

View file

@ -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 { '<leader>si', '<cmd>:IndentBlanklineToggle<cr>' }
end

View file

@ -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 { '<c-n>', '<cmd>NvimTreeToggle<cr>' }
nmap { '<leader>n', '<cmd>NvimTreeFindFileToggle<cr>' }
end

View file

@ -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 { '<leader>w', '<cmd>StripWhitespace<cr>' }

View file

@ -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 }

View file

@ -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 { '<leader>sc', '<cmd>lua require"fs.config.virt-column".toggle()<cr>' }
-- show/hide virtual colorcolumn
nmap { '<leader>sc', [[<cmd>lua require'fs.config.virt-column'.toggle()<cr>]] }
end
return { config = config, toggle = toggle }

View file

@ -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