gitsigns.nvim
gitsigns.nvim copied to clipboard
Incorporate `cursorline` highlighting in sign column
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:

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

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.
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.
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!
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)
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
Without modification
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",
})
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
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 😬
Fwiw I have given up on trying to get it, and I have disabled culhl for all signs