gitsigns.nvim icon indicating copy to clipboard operation
gitsigns.nvim copied to clipboard

Incorporate `cursorline` highlighting in sign column

Open andmis opened this issue 2 years ago • 8 comments

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 avatar May 12 '22 17:05 andmis

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 avatar May 12 '22 17:05 lewis6991

Are you sure that this is actually possible/straightforward in Neovim as it currently is? As in, are you sure that the highlight group of the sign text is changed depending on whether the cursor is on the same line as the sign, when cursorline=number?

I am just asking because I've noticed that this is a common trend, that the cursorline highlighting does not get applied to the sign column (for example I observed the same thing with nvim-dap breakpoints).


Edit: Never mind! I found culhl in sign_define! Sorry for the spam!

andmis avatar May 13 '22 18:05 andmis

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)

fwrs avatar Aug 23 '23 03:08 fwrs

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 avatar Oct 04 '23 06:10 m-wells

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",
})

m-wells avatar Oct 04 '23 06:10 m-wells

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

mizlan avatar Mar 02 '24 01:03 mizlan

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 😬

fwrs avatar Mar 04 '24 21:03 fwrs

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

mizlan avatar Mar 04 '24 21:03 mizlan