vim: factor out highlight function into fs.util
This commit is contained in:
parent
c79b16f79a
commit
1529b88178
5 changed files with 51 additions and 31 deletions
|
@ -1,11 +1,14 @@
|
||||||
local nmap = require'fs.util'.nmap
|
local util = require'fs.util'
|
||||||
|
local nmap = util.nmap
|
||||||
|
local colors = util.colors()
|
||||||
|
local highlight = util.highlight
|
||||||
|
|
||||||
local config = function()
|
local config = function()
|
||||||
vim.g.indent_blankline_enabled = false
|
vim.g.indent_blankline_enabled = false
|
||||||
|
|
||||||
require'indent_blankline'.setup()
|
require'indent_blankline'.setup()
|
||||||
|
|
||||||
vim.cmd [[highlight IndentBlanklineChar ctermfg=10]]
|
highlight('IndentBlanklineChar') { fg = colors.base01 }
|
||||||
|
|
||||||
nmap { '<leader>si', '<cmd>:IndentBlanklineToggle<cr>' }
|
nmap { '<leader>si', '<cmd>:IndentBlanklineToggle<cr>' }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
local nmap = require'fs.util'.nmap
|
local util = require'fs.util'
|
||||||
local colors = require'fs.util'.colors()
|
local nmap = util.nmap
|
||||||
|
local colors = util.colors()
|
||||||
|
local highlight = util.highlight
|
||||||
|
|
||||||
-- helper to set vim.g options that will be moved to setup() later
|
-- helper to set vim.g options that will be moved to setup() later
|
||||||
local function set_globals(tbl)
|
local function set_globals(tbl)
|
||||||
|
@ -9,14 +11,6 @@ local function set_globals(tbl)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function highlight(group, color)
|
|
||||||
if vim.opt.termguicolors:get() then
|
|
||||||
vim.cmd(vim.fn.printf('highlight %s guifg=%s', group, color))
|
|
||||||
else
|
|
||||||
vim.cmd(vim.fn.printf('highlight %s ctermfg=%d', group, color))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local global_opts ={
|
local global_opts ={
|
||||||
add_trailing = 1, -- add trailing / to folders
|
add_trailing = 1, -- add trailing / to folders
|
||||||
group_empty = 1, -- folders that contain only one folder are grouped
|
group_empty = 1, -- folders that contain only one folder are grouped
|
||||||
|
@ -24,7 +18,7 @@ local global_opts ={
|
||||||
git_hl = 1, -- enable highlight based on git attributes
|
git_hl = 1, -- enable highlight based on git attributes
|
||||||
|
|
||||||
icons = {
|
icons = {
|
||||||
default = '', -- defailt icon for files
|
default = '', -- default icon for files
|
||||||
symlink = '', -- default icon for symlinks
|
symlink = '', -- default icon for symlinks
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -49,14 +43,14 @@ local nvim_tree_config = {
|
||||||
local config = function()
|
local config = function()
|
||||||
require'nvim-tree'.setup(nvim_tree_config)
|
require'nvim-tree'.setup(nvim_tree_config)
|
||||||
|
|
||||||
highlight('NvimTreeSpecialFile' , colors.base2 )
|
highlight('NvimTreeSpecialFile') { fg = colors.base2 }
|
||||||
highlight('NvimTreeIndentMarker' , colors.base01 )
|
highlight('NvimTreeIndentMarker') { fg = colors.base01 }
|
||||||
highlight('NvimTreeGitStaged' , colors.green )
|
highlight('NvimTreeGitStaged') { fg = colors.green }
|
||||||
highlight('NvimTreeGitRenamed' , colors.yellow )
|
highlight('NvimTreeGitRenamed') { fg = colors.yellow }
|
||||||
highlight('NvimTreeGitNew' , colors.yellow )
|
highlight('NvimTreeGitNew') { fg = colors.yellow }
|
||||||
highlight('NvimTreeGitDirty' , colors.yellow )
|
highlight('NvimTreeGitDirty') { fg = colors.yellow }
|
||||||
highlight('NvimTreeGitDeleted' , colors.orange )
|
highlight('NvimTreeGitDeleted') { fg = colors.orange }
|
||||||
highlight('NvimTreeGitMerge' , colors.red )
|
highlight('NvimTreeGitMerge') { fg = colors.red }
|
||||||
|
|
||||||
nmap { '<c-n>', '<cmd>NvimTreeToggle<cr>' }
|
nmap { '<c-n>', '<cmd>NvimTreeToggle<cr>' }
|
||||||
nmap { '<leader>n', '<cmd>NvimTreeFindFileToggle<cr>' }
|
nmap { '<leader>n', '<cmd>NvimTreeFindFileToggle<cr>' }
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
|
local util = require'fs.util'
|
||||||
|
local C = util.colors()
|
||||||
|
local highlight = util.highlight
|
||||||
|
|
||||||
local config = function()
|
local config = function()
|
||||||
vim.cmd [[
|
vim.cmd [[silent! colorscheme solarized]]
|
||||||
silent! colorscheme solarized
|
|
||||||
highlight Normal ctermbg=NONE " transparent background
|
highlight('Normal') { bg = 'NONE' } -- transparent background
|
||||||
highlight NonText cterm=NONE ctermfg=10 " subtle EOL symbols
|
highlight('NonText') { fg = C.base02, attrs = 'NONE' } -- subtle EOL symbols
|
||||||
highlight Whitespace cterm=NONE ctermfg=9 " orange listchars
|
highlight('Whitespace') { fg = C.orange } -- listchars
|
||||||
highlight SpellBad ctermfg=3 " yellow spelling mistakes
|
highlight('SpellBad') { fg = C.yellow }
|
||||||
highlight QuickFixLine ctermfg=3 ctermbg=0 " yellow selected quickfix item
|
highlight('QuickFixLine') { fg = C.yellow, bg = C.base02 } -- selected quickfix item
|
||||||
]]
|
highlight('CursorLineNr') { fg = C.yellow, attrs = 'NONE' } -- current line number
|
||||||
end
|
end
|
||||||
|
|
||||||
return { config = config }
|
return { config = config }
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
local nmap = require'fs.util'.nmap
|
local util = require'fs.util'
|
||||||
|
local nmap = util.nmap
|
||||||
|
local colors = util.colors()
|
||||||
|
local highlight = util.highlight
|
||||||
|
|
||||||
local toggle = function()
|
local toggle = function()
|
||||||
if vim.o.colorcolumn == '' then
|
if vim.o.colorcolumn == '' then
|
||||||
|
@ -11,7 +14,7 @@ end
|
||||||
local config = function()
|
local config = function()
|
||||||
require'virt-column'.setup { char = '│' }
|
require'virt-column'.setup { char = '│' }
|
||||||
|
|
||||||
vim.cmd [[highlight VirtColumn cterm=NONE ctermfg=0]]
|
highlight('VirtColumn') { fg = colors.base02, attrs = 'NONE' }
|
||||||
|
|
||||||
nmap { '<leader>sc', '<cmd>lua require"fs.config.virt-column".toggle()<cr>' }
|
nmap { '<leader>sc', '<cmd>lua require"fs.config.virt-column".toggle()<cr>' }
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,5 +57,21 @@ M.colors = function(gui)
|
||||||
}
|
}
|
||||||
end
|
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'
|
||||||
|
|
||||||
|
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, ' '))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue