Closed domsch1988 closed 4 months ago
Thanks for the suggestion!
This is already more or less possible with 'mini.hipatterns' by creating pattern for characters to cover and showing virtual text on top of them. There is even a similar example in its help.
Toggling should also possible in separate function, albeit not as straightforward: modify directly MiniHipatterns.config.highlighters
to toggle certain highlighter (assign to table/nil
to enable/disable) and follow by vim.cmd('edit')
to "restart" all highlighters.
Closing as not planned.
Thanks for the hint in the right direction. I'll leave what i came up with here, if anyone stumbles onto this:
local hipatterns = require('mini.hipatterns')
local censor_extmark_opts = function(_, match, _)
local mask = string.rep('*', vim.fn.strchars(match))
return {
virt_text = { { mask, 'Comment' } },
virt_text_pos = 'overlay',
priority = 200,
right_gravity = false,
}
end
local password_table = { pattern = {
'password: ()%S+()',
'password_usr: ()%S+()',
}, group = '', extmark_opts = censor_extmark_opts }
hipatterns.setup({
highlighters = {
-- Cloaking Passwords
pw = password_table,
},
})
vim.keymap.set("n", "<leader>up", function()
if next(hipatterns.config.highlighters.pw) == nil then
hipatterns.config.highlighters.pw = password_table
else
hipatterns.config.highlighters.pw = {}
end
vim.cmd('edit')
end, { desc = 'Toggle Password Cloaking' })
This avoids having to track the wanted Password patterns in two spots (hipatterns setup and keymap).
Contributing guidelines
Module(s)
mini.cloak
Description
I'm using nvim at work also to screenshare. We often work on repositories that contain some form of secrects. They are fine in there, but we are concious about showing them on a Video Call. Especially when calling with customers. For this purpose, i've been using cloak.nvim but thought that this is the kind of "small" problemsolver that would fit mini pretty well.
The basic idea is to define certain keywords that precede a "secret" of some form, and then hide everything after that behind a cloaking character. Ideally yanking still gets the original content, and the cloaking is toggleable.