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

Add Highlight Groups For Even and Odd Lines #20092

Closed
austinliuigi opened this issue Sep 6, 2022 · 8 comments
Closed

Add Highlight Groups For Even and Odd Lines #20092

austinliuigi opened this issue Sep 6, 2022 · 8 comments
Labels
enhancement feature request

Comments

@austinliuigi
Copy link

Feature already in Vim?

No

Feature description

Is your feature request about something that is currently impossible or hard to do? Please describe the problem.

I think it's nice for even and odd lines to have different highlights. It lets me quickly see which number in the line-number column any particular line corresponds to, regardless of how much whitespace is in front of it. It's a nice quality of life improvement when using relative numbers.

Currently, chrisbra's "DynamicSigns" plugin implements this functionality by adding signs to each line and giving them a different highlight whether they're even or odd. However, when a file has a relatively large number of lines, this causes an extreme slowdown and becomes almost unusable. Additionally, there are times when the signs to not update automatically.

Describe the solution you'd like

A builtin option of highlighting even and odd lines differently (LineEven and LineOdd hl-groups?). Here is an image using the DynamicSigns plugin:

image

Additional context

I have no idea about the feasibility of this, but I'm hoping it's a feature that is reasonable to add.

The highlighting doesn't even necessarily need to be tied to the line; as long as adjacent lines have different highlights, it makes it easier to see what line number each line corresponds to.

@austinliuigi austinliuigi added the enhancement feature request label Sep 6, 2022
@clason
Copy link
Member

clason commented Sep 6, 2022

I don't think this needs to be in core; (extmark) signs are much more efficient in Neovim, so a (Lua) plugin still sounds like the right option here. (@lewis6991 ?)

@zeertzjq
Copy link
Member

zeertzjq commented Sep 6, 2022

A problem with implementing this as highlight groups is that this behavior is not wanted for every window/buffer, so if these highlight groups are added, one needs to override more highlight groups to change the background colors of a specific window.

@lewis6991
Copy link
Member

This appears to work:

local ns = vim.api.nvim_create_namespace('evenoddlines')

vim.api.nvim_set_decoration_provider(ns, {
  on_win = function()
  end,
  on_line = function(_, _, buf, row)
    if row % 2 == 0 then
      vim.api.nvim_buf_set_extmark(buf, ns, row, 0, {
        end_row = row + 1,
        hl_group = 'Visual',
        hl_eol = true,
        ephemeral = true
      })
    end
  end
})

I did try with line_hl_group, however that doesn't appear to work with ephemeral = true.

@notomo
Copy link
Sponsor Contributor

notomo commented Sep 6, 2022

FYI https://github.com/notomo/zebrazone.nvim

@clason
Copy link
Member

clason commented Sep 6, 2022

Looks like there already is a fine plugin, so I'm closing this as not needed in core.

@clason clason closed this as completed Sep 6, 2022
@austinliuigi
Copy link
Author

Thank you!

@neovim-discourse
Copy link

This issue has been mentioned on Neovim Discourse. There might be relevant details there:

https://neovim.discourse.group/t/init-lua-highlight-every-even-lines/3963/2

@justinmk
Copy link
Member

justinmk commented Jun 5, 2023

With :help 'statuscolumn' in Nvim 0.9 there is now a more "native" way to achieve this. See also https://github.com/luukvbaal/statuscol.nvim for even more examples.

@neovim neovim locked as resolved and limited conversation to collaborators Jun 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement feature request
Projects
None yet
Development

No branches or pull requests

7 participants