Skip to content

Highlight trailing whitespaces #762

Closed Answered by lukas-reineke
horseinthesky asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@horseinthesky
Comment options

@lukas-reineke
Comment options

Answer selected by lukas-reineke
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants