From e66fdc1eac28e0fef95b50d126d5ea4ca9c1cb70 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 8 Sep 2026 23:24:45 +0800 Subject: [PATCH] vim-patch:9.2.1038: CursorLineFold/Sign highlighting depends on 'cursorlineopt' (#41785) Problem: CursorLineFold and CursorLineSign are only applied when 'cursorlineopt' contains "number" or is "both" (Evgeni Chasnovski). Solution: Apply those groups whenever 'cursorline' is set, independent of 'cursorlineopt' (Vrushali Zampalkar). fixes: vim/vim#20480 closes: vim/vim#21112 https://github.com/vim/vim/commit/1f8d3c44c5bd5a3d5032b3fc53e9d3aa1052583c Co-authored-by: Vrushali-Z --- runtime/doc/news.txt | 2 ++ runtime/doc/options.txt | 9 ++++- runtime/lua/vim/_meta/options.gen.lua | 9 ++++- src/nvim/drawline.c | 7 ++-- src/nvim/options.lua | 9 ++++- test/functional/ui/fold_spec.lua | 8 ++--- test/functional/ui/sign_spec.lua | 2 +- test/old/testdir/test_cursorline.vim | 50 +++++++++++++++++++++++++++ 8 files changed, 84 insertions(+), 12 deletions(-) diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 66b9a32c44..8e8ae69b12 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -551,6 +551,8 @@ These existing features changed their behavior. requires it to be installed). • `:helptags ALL` reports |E152| for "doc" directories it cannot write, instead of silently skipping them. +• The highlighting groups |hl-CursorLineFold| and |hl-CursorLineSign| are + always used when 'cursorline' is set. ============================================================================== REMOVED FEATURES *news-removed* diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 0609588a65..5581733fbc 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2098,7 +2098,14 @@ A jump table for the options with a short description can be found at |Q_op|. *'cursorline'* *'cul'* *'nocursorline'* *'nocul'* 'cursorline' 'cul' boolean (default off) local to window - Highlight the text line of the cursor with CursorLine |hl-CursorLine|. + Highlighting used for the line the cursor is on: + + CursorLine the text line |hl-CursorLine| + CursorLineFold the fold column |hl-CursorLineFold| + CursorLineSign the sign column |hl-CursorLineSign| + CursorLineNr the line number, when 'cursorlineopt' contains + "number" |hl-CursorLineNr| + Useful to easily spot the cursor. Will make screen redrawing slower. When Visual mode is active the highlighting isn't used to make it easier to see the selected text. diff --git a/runtime/lua/vim/_meta/options.gen.lua b/runtime/lua/vim/_meta/options.gen.lua index 7354c40f1e..e6e1e372f4 100644 --- a/runtime/lua/vim/_meta/options.gen.lua +++ b/runtime/lua/vim/_meta/options.gen.lua @@ -1624,7 +1624,14 @@ vim.o.cuc = vim.o.cursorcolumn vim.wo.cursorcolumn = vim.o.cursorcolumn vim.wo.cuc = vim.wo.cursorcolumn ---- Highlight the text line of the cursor with CursorLine `hl-CursorLine`. +--- Highlighting used for the line the cursor is on: +--- +--- CursorLine the text line `hl-CursorLine` +--- CursorLineFold the fold column `hl-CursorLineFold` +--- CursorLineSign the sign column `hl-CursorLineSign` +--- CursorLineNr the line number, when 'cursorlineopt' contains +--- "number" `hl-CursorLineNr` +--- --- Useful to easily spot the cursor. Will make screen redrawing slower. --- When Visual mode is active the highlighting isn't used to make it --- easier to see the selected text. diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 47eff705cb..a3ac21cf23 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -480,12 +480,11 @@ static void draw_col_fill(winlinevars_T *wlv, schar_T fillchar, int width, int a } } -/// Return true if CursorLineSign highlight is to be used. +/// Return true if CursorLineSign / CursorLineFold highlight is to be used. +/// This depends only on 'cursorline', not on 'cursorlineopt'. bool use_cursor_line_highlight(win_T *wp, linenr_T lnum) { - return wp->w_p_cul - && lnum == wp->w_cursorline - && (wp->w_p_culopt_flags & kOptCuloptFlagNumber); + return wp->w_p_cul && lnum == wp->w_cursorline; } /// Setup for drawing the 'foldcolumn', if there is one. diff --git a/src/nvim/options.lua b/src/nvim/options.lua index c23e6e7e0f..8b0aec5a6a 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2233,7 +2233,14 @@ local options = { abbreviation = 'cul', defaults = false, desc = [=[ - Highlight the text line of the cursor with CursorLine |hl-CursorLine|. + Highlighting used for the line the cursor is on: + + CursorLine the text line |hl-CursorLine| + CursorLineFold the fold column |hl-CursorLineFold| + CursorLineSign the sign column |hl-CursorLineSign| + CursorLineNr the line number, when 'cursorlineopt' contains + "number" |hl-CursorLineNr| + Useful to easily spot the cursor. Will make screen redrawing slower. When Visual mode is active the highlighting isn't used to make it easier to see the selected text. diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index 9df4aae500..3124d95461 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -194,7 +194,7 @@ describe('folded lines', function() [2:---------------------------------------------]|*7 [3:---------------------------------------------]| ## grid 2 - {7:+ }{8: 1 }{101:^+-- 4 lines: This is a················}| + {10:+ }{8: 1 }{101:^+-- 4 lines: This is a················}| {7: }{8: 5 }in his cave. | {7: }{8: 6 } | {1:~ }|*4 @@ -207,7 +207,7 @@ describe('folded lines', function() [2:---------------------------------------------]|*7 [3:---------------------------------------------]| ## grid 2 - {7:+ }{8: 1 }{101:^This is a······························}| + {10:+ }{8: 1 }{101:^This is a······························}| {7: }{8: 5 }in his cave. | {7: }{8: 6 } | {1:~ }|*4 @@ -218,7 +218,7 @@ describe('folded lines', function() else if foldtext then screen:expect([[ - {7:+ }{8: 1 }{101:^+-- 4 lines: This is a················}| + {10:+ }{8: 1 }{101:^+-- 4 lines: This is a················}| {7: }{8: 5 }in his cave. | {7: }{8: 6 } | {1:~ }|*4 @@ -226,7 +226,7 @@ describe('folded lines', function() ]]) else screen:expect([[ - {7:+ }{8: 1 }{101:^This is a······························}| + {10:+ }{8: 1 }{101:^This is a······························}| {7: }{8: 5 }in his cave. | {7: }{8: 6 } | {1:~ }|*4 diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua index c270f9a3a2..9ce84cfddc 100644 --- a/test/functional/ui/sign_spec.lua +++ b/test/functional/ui/sign_spec.lua @@ -162,7 +162,7 @@ describe('Signs', function() exec('set cursorline cursorlineopt=line') screen:expect([[ {101:>>}a | - {101:>>}{21:^b }| + {9:>>}{21:^b }| {101:>>}c | {1:~ }|*10 | diff --git a/test/old/testdir/test_cursorline.vim b/test/old/testdir/test_cursorline.vim index 4af85ede01..9ec4c67bf9 100644 --- a/test/old/testdir/test_cursorline.vim +++ b/test/old/testdir/test_cursorline.vim @@ -107,6 +107,56 @@ func Test_cursorline_highlight2() endtry endfunc +func Test_cursorline_fold_sign_independent_of_culopt() + " CursorLineFold/CursorLineSign follow 'cursorline', not 'cursorlineopt'. + CheckOption cursorlineopt + CheckFeature signs + CheckFeature folding + + call s:test_windows(10, 20) + try + call setline(1, repeat(['aaaa'], 5)) + setl number numberwidth=4 signcolumn=yes foldcolumn=1 + hi FoldColumn ctermbg=1 guibg=Red + hi CursorLineFold ctermbg=2 guibg=Green + hi SignColumn ctermbg=3 guibg=Yellow + hi CursorLineSign ctermbg=4 guibg=Blue + + setl nocursorline + redraw + let fold_off = screenattr(1, 1) + let sign_off = screenattr(1, 2) + + " 'cursorlineopt' is "line" only: fold/sign on the cursor line still + " use CursorLineFold / CursorLineSign. + setl cursorline cursorlineopt=line + redraw + call assert_notequal(fold_off, screenattr(1, 1)) + call assert_notequal(sign_off, screenattr(1, 2)) + call assert_equal(fold_off, screenattr(2, 1)) + call assert_equal(sign_off, screenattr(2, 2)) + + setl cursorlineopt=number + redraw + call assert_notequal(fold_off, screenattr(1, 1)) + call assert_notequal(sign_off, screenattr(1, 2)) + + setl cursorlineopt=both + redraw + call assert_notequal(fold_off, screenattr(1, 1)) + call assert_notequal(sign_off, screenattr(1, 2)) + finally + setl number& numberwidth& signcolumn& foldcolumn& cursorline& cursorlineopt& + hi clear FoldColumn + hi clear CursorLineFold + hi clear SignColumn + hi clear CursorLineSign + hi default link CursorLineFold FoldColumn + hi default link CursorLineSign SignColumn + call s:close_windows() + endtry +endfunc + func Test_cursorline_screenline() CheckScreendump CheckOption cursorlineopt