[mini.hipatterns] highlighting of keywords like todo-comments
#783
Replies: 2 comments
-
Oh, that looks nice! I am personally not a fan of highlighting whole line containing the keyword, but it certainly look nice. |
Beta Was this translation helpful? Give feedback.
-
@pkazmier I think this can even be simplified by passing an array of patterns for the keyword + the colon mini.nvim/doc/mini-hipatterns.txt Lines 273 to 274 in a3f2746 Update: ignore this, it won't work in your case. Here is what I'm doing (I now it can be simplified, still didn't make up my mind on highlighting the whole line or not) local hipatterns = require 'mini.hipatterns'
local highlighters = {}
for _, word in ipairs {
'todo',
'note',
'hack',
'fixme',
{ 'warn', 'hack' },
{ 'bug', 'fixme' },
} do
local w = type(word) == 'table' and word[1] or word
local hl = type(word) == 'table' and word[2] or word
highlighters[w] = {
pattern = {
string.format('()@%s()', w:upper()),
string.format('()%s()', w:upper()),
string.format('%s():()', w:upper()),
string.format('%s ().*()', w:upper()),
string.format('%s: ().*()', w:upper()),
},
group = string.format(
'MiniHipatterns%s',
hl:sub(1, 1):upper() .. hl:sub(2)
),
}
end
hipatterns.setup {
highlighters = vim.tbl_extend('force', highlighters, {
-- Highlight hex color strings (`#rrggbb`) using that color
hex_color = hipatterns.gen_highlighter.hex_color(),
}),
} looks like this |
Beta Was this translation helpful? Give feedback.
-
Thought I'd share my highlighting rules for mini.hipatterns, which mimics folke's
todo-comments
in the event others might be interested.Specifically, it ensures the keyword's reverse text has a single space on the left and right side of the word. The space on the right side is created by hiding the colon using the same fg and bg color. Finally, it uses the reverse color as the foreground for the remainder of the line.
For comparison, here is the version using
mini.extras.gen_highlighter
:Beta Was this translation helpful? Give feedback.
All reactions