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

Incorporate cursorline highlighting in sign column #563

Closed
andmis opened this issue May 12, 2022 · 15 comments
Closed

Incorporate cursorline highlighting in sign column #563

andmis opened this issue May 12, 2022 · 15 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@andmis
Copy link

andmis commented May 12, 2022

Is your feature request related to a problem? Please describe.

I use set signcolumn=number and have my cursor line highlighting extending across the number column like so:

image

I can't find a way to make the CursorLine background apply to the signs:

image

Describe the solution you'd like

I would like the lighter-shaded background to extend all the way to the left side of "Another new line".

Describe alternatives you've considered

I've played around with the Neovim and gitsigns highlighting a bunch and cannot get this to happen.

@andmis andmis added the enhancement New feature or request label May 12, 2022
@lewis6991
Copy link
Owner

lewis6991 commented May 12, 2022

This will require passing the culhl argument to sign_define() (or cursorline_hl_group for extmarks), and also require us to define cursorline variants for all the required sign highlights.

@lewis6991 lewis6991 added the good first issue Good for newcomers label May 12, 2022
@andmis

This comment was marked as resolved.

@fwrs
Copy link

fwrs commented Aug 23, 2023

Here's a simple solution that makes all signs use the CursorLine background:

require("gitsigns").setup()
vim.defer_fn(function()
    local cl_bg = vim.api.nvim_get_hl(0, { name = "CursorLine", link = false }).bg
    for _, sign in ipairs(vim.fn.sign_getdefined()) do
        local hl = vim.api.nvim_get_hl(0, { name = sign.texthl, link = false })
        local name = sign.texthl .. "Cul"
        vim.api.nvim_set_hl(0, name, { fg = hl.fg, bg = cl_bg })
        vim.fn.sign_define(sign.name, { culhl = name })
    end
end, 100)

@m-wells
Copy link

m-wells commented Oct 4, 2023

I had to modify @fwrs solution slightly.

require 'gitsigns'.setup(opts)
vim.defer_fn(function()
  local bg = vim.api.nvim_get_hl(0, { name = "SignColumn", link = false }).bg
  local cl_bg = vim.api.nvim_get_hl(0, { name = "CursorLineSign", link = false }).bg
  for _, sign in ipairs(vim.fn.sign_getdefined()) do
    local hl = vim.api.nvim_get_hl(0, { name = sign.texthl, link = false })
    local name = sign.texthl
    vim.api.nvim_set_hl(0, name, { fg = hl.fg, bg = bg })
    name = name .. "Cul"
    vim.api.nvim_set_hl(0, name, { fg = hl.fg, bg = cl_bg })
    vim.fn.sign_define(sign.name, { culhl = name })
  end
end, 10)

With modification
image
Without modification
image

@m-wells
Copy link

m-wells commented Oct 4, 2023

I also have the following to get the SignColumn to follow Normal and NormalNC.

vim.api.nvim_create_autocmd({ "BufWinEnter", "WinEnter" }, {
  callback = function()
    local bg = vim.api.nvim_get_hl(0, { name = "Normal", link = false }).bg
    vim.cmd("highlight! SignColumn guibg=" .. bg)
  end,
  desc = "For active window, set SignColumn background to Normal",
})

vim.api.nvim_create_autocmd("WinLeave", {
  callback = function()
    local bg = vim.api.nvim_get_hl(0, { name = "NormalNC", link = false }).bg
    vim.cmd("highlight! SignColumn guibg=" .. bg)
  end,
  desc = "For inactive window, set SignColumn background to NormalNC",
})

@mizlan
Copy link

mizlan commented Mar 2, 2024

These solutions work for signs, but newer signs use extmarks and extmark namespaces instead. So the above doesn't quite work for me. Might write an updated solutions

@fwrs
Copy link

fwrs commented Mar 4, 2024

I would greatly appreciate a solution that incorporates extmarks!
At the moment I just do require("gitsigns").setup { _extmark_signs = false } while hoping that this issue will receive a proper fix 😬

@mizlan
Copy link

mizlan commented Mar 4, 2024

Fwiw I have given up on trying to get it, and I have disabled culhl for all signs

@lewis6991
Copy link
Owner

Done in #1097

@bluz71
Copy link
Contributor

bluz71 commented Jul 24, 2024

This is an excellent enhancement, thanks @apollo1321 and @lewis6991.

@cmvanb
Copy link

cmvanb commented Jul 24, 2024

I've been waiting for this feature for a while, so I was excited to get the notification!

Sadly it's not working for me...

2024-07-24--10-53-02

@bluz71
Copy link
Contributor

bluz71 commented Jul 24, 2024

@cmvanb,

Your colorscheme needs to support the new GitSigns*Cul highlight groups.

In my experimentation, this feature works well.

@cmvanb
Copy link

cmvanb commented Jul 24, 2024

Thanks, I added the new highlight groups and it works.

@mizlan
Copy link

mizlan commented Jul 24, 2024

Is anybody noticing breakage with statuscol.nvim? Works for me if I disable statuscol.nvim but breaks with it:
Screenshot 2024-07-24 at 10 01 09 AM
Screenshot 2024-07-24 at 10 00 55 AM

Might be statuscol.nvim issue

@apollo1321
Copy link
Contributor

Created pr to fix this behavior: luukvbaal/statuscol.nvim#133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
8 participants