Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background color indentation guides to be a single char wide #950

Open
hernancerm opened this issue Nov 22, 2024 · 5 comments
Open

Background color indentation guides to be a single char wide #950

hernancerm opened this issue Nov 22, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@hernancerm
Copy link

hernancerm commented Nov 22, 2024

Problem

The background color indentation guides occupy the full indent depth. For exampe, if the code is indented at 4 spaces, as in the screenshot below, then the background color has a width of 4 characters.

The problem I see with this behavior is that the required alternation of highlight groups, such as "CursorColumn" and "Whitespace" as per the README.md, results in some indentations of the same type of structure not being highlighted, which is confusing at least for me.

image

Expected behavior

There exists some way to configure the background color indentation guides to look as in the image below. That is to say, the indentation guides are drawn using a single background color of width 1 char and starting where the indent begins.

image

I created the image using https://github.com/preservim/vim-indent-guides. Although vim-indent-guides is able to achieve the look I want, the plugin has issues such as not being able to show the background color on blank lines and it repeats the indentation guide on line continuations.

Thx for this plugin :) If you feel this is out of scope or too niche, feel free to close.

@hernancerm hernancerm added the enhancement New feature or request label Nov 22, 2024
@lukas-reineke
Copy link
Owner

There exists some way to configure the background color indentation guides

There is. You can set the highlight group for both the indentation, and the whitespace. The background color example in the readme sets it for the whitespace, you can just switch it to the indentation.

This should do what you want.

require("ibl").setup {
    indent = {
        highlight = "ColorColumn",
    },
}

@hernancerm
Copy link
Author

The reason for my interest on this one char width feature is this: I would like to display the multispace char of listchars and the indentation guides at the same time without omitting the multispace char at the position of the indent guide. Following your suggestion gets very close, but the multispace chars "beneath" the indent guides are not shown, as they are replaced by the space char (ok since that's how I configured it in the snippet below).

require("ibl").setup {
  indent = {
    highlight = "ColorColumn",
    char = " "
  },
  scope = {
    enabled = false
  }
}

image

I could change the char for the indent to match listchars, but then the empty lines become deceiving:

...
    char = "·"
...

image

@lukas-reineke
Copy link
Owner

I see.

It's currently not supported to display different indent characters for blank vs non-blank lines, out of the box.

You can use a hook to make this yourself
Something like this:

local hooks = require "ibl.hooks"
hooks.register(hooks.type.VIRTUAL_TEXT, function(_, bufnr, row, virt_text)
    local text = vim.api.nvim_buf_get_text(bufnr, row, 0, row, -1, {})[1]
    if #text == 0 then
        for _, vt in ipairs(virt_text) do
            vt[1] = " "
        end
    end
    return virt_text
end)

There might be edge cases, and maybe the performance won't be the best.

I'll think about adding a native option for this.

@hernancerm
Copy link
Author

Thank you, for the code and for considering implementing the capability into the plugin. The hook you provided achieves the behavior I'm looking for. I'll keep using it for some time to see if this indentation guide style grows on me.

@hernancerm
Copy link
Author

I'll keep using it for some time to see if this indentation guide style grows on me.

FWIW I've used this indentation style since my last comment in this issue and yes, it has grown on me. I have not been bothered by the performance of the hook, so at least for me the hook is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants