Highlight trailing whitespaces #762
-
Hello. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
There is no option, but you can make a hook for this. This is a simple example, there might be edge cases update this as you need. local utils = require "ibl.utils"
local hooks = require "ibl.hooks"
hooks.register(hooks.type.VIRTUAL_TEXT, function(_, bufnr, row, virt_text)
-- Get the line for this row
local line = vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1]
-- Check if it has trailing whitespace
if #line == 0 or #line ~= #utils.get_whitespace(line) then
return virt_text
end
-- Iterate over the virtual text
for i, cell in ipairs(virt_text) do
-- Iterate over each virtual text cell
for j, highlight_group in ipairs(cell[2]) do
-- Overwrite any highlight that is whitespace
if vim.startswith(highlight_group, "@ibl.whitespace") then
virt_text[i][2][j] = "Error" -- Change this to whatever highlight group you want
end
end
end
return virt_text
end) |
Beta Was this translation helpful? Give feedback.
-
Thank you for the explanation. I've found this small plugin that does the trick =) |
Beta Was this translation helpful? Give feedback.
There is no option, but you can make a hook for this.
This is a simple example, there might be edge cases update this as you need.