Skip to content

Commit 410e98a

Browse files
committed
patch 8.1.2019: 'cursorline' always highlights the whole line
Problem: 'cursorline' always highlights the whole line. Solution: Add 'cursorlineopt' to specify what is highlighted. (closes #4693)
1 parent e5fbd73 commit 410e98a

File tree

13 files changed

+172
-9
lines changed

13 files changed

+172
-9
lines changed

runtime/doc/options.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,13 +2461,26 @@ A jump table for the options with a short description can be found at |Q_op|.
24612461
local to window
24622462
{not available when compiled without the |+syntax|
24632463
feature}
2464-
Highlight the screen line of the cursor with CursorLine
2465-
|hl-CursorLine|. Useful to easily spot the cursor. Will make screen
2466-
redrawing slower.
2464+
Highlight the text line of the cursor with CursorLine |hl-CursorLine|.
2465+
Useful to easily spot the cursor. Will make screen redrawing slower.
24672466
When Visual mode is active the highlighting isn't used to make it
24682467
easier to see the selected text.
24692468

24702469

2470+
*'cursorlineopt'* *'culopt'*
2471+
'cursorlineopt' 'culopt' string (default: "both")
2472+
local to window
2473+
{not in Vi}
2474+
{not available when compiled without the |+syntax|
2475+
feature}
2476+
Settings for how 'cursorline' is displayed. Valid values:
2477+
"line" Highlight the text line of the cursor with
2478+
CursorLine |hl-CursorLine|.
2479+
"number" Highlight the line number of the cursor with
2480+
CursorLineNr |hl-CursorLineNr|.
2481+
"both" Highlight as both "line" and "number" are set.
2482+
2483+
24712484
*'debug'*
24722485
'debug' string (default "")
24732486
global

runtime/doc/quickref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ Short explanation of each option: *option-list*
670670
'cursorbind' 'crb' move cursor in window as it moves in other windows
671671
'cursorcolumn' 'cuc' highlight the screen column of the cursor
672672
'cursorline' 'cul' highlight the screen line of the cursor
673+
'cursorlineopt' 'culopt' settings for 'cursorline'
673674
'debug' set to "msg" to see all error messages
674675
'define' 'def' pattern to be used to find a macro definition
675676
'delcombine' 'deco' delete combining characters on their own

runtime/doc/syntax.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5042,7 +5042,8 @@ IncSearch 'incsearch' highlighting; also used for the text replaced with
50425042
LineNr Line number for ":number" and ":#" commands, and when 'number'
50435043
or 'relativenumber' option is set.
50445044
*hl-CursorLineNr*
5045-
CursorLineNr Like LineNr when 'cursorline' or 'relativenumber' is set for
5045+
CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' is
5046+
set to "number" or "both", or 'relativenumber' is set, for
50465047
the cursor line.
50475048
*hl-MatchParen*
50485049
MatchParen The character under the cursor or just before it, if it

runtime/optwin.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ if has("syntax")
429429
call append("$", "cursorline\thighlight the screen line of the cursor")
430430
call append("$", "\t(local to window)")
431431
call <SID>BinOptionL("cul")
432+
call append("$", "cursorlineopt\tspecifies which area 'cursorline' highlights")
433+
call append("$", "\t(local to window)")
434+
call <SID>OptionL("culopt")
432435
call append("$", "colorcolumn\tcolumns to highlight")
433436
call append("$", "\t(local to window)")
434437
call <SID>OptionL("cc")

src/option.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
#ifdef FEAT_SYN_HL
239239
# define PV_CUC OPT_WIN(WV_CUC)
240240
# define PV_CUL OPT_WIN(WV_CUL)
241+
# define PV_CULOPT OPT_WIN(WV_CULOPT)
241242
# define PV_CC OPT_WIN(WV_CC)
242243
#endif
243244
#ifdef FEAT_STL_OPT
@@ -993,6 +994,13 @@ static struct vimoption options[] =
993994
(char_u *)NULL, PV_NONE,
994995
#endif
995996
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
997+
{"cursorlineopt", "culopt", P_STRING|P_VI_DEF|P_RWIN,
998+
#ifdef FEAT_SYN_HL
999+
(char_u *)VAR_WIN, PV_CULOPT,
1000+
#else
1001+
(char_u *)NULL, PV_NONE,
1002+
#endif
1003+
{(char_u *)"both", (char_u *)0L} SCTX_INIT},
9961004
{"debug", NULL, P_STRING|P_VI_DEF,
9971005
(char_u *)&p_debug, PV_NONE,
9981006
{(char_u *)"", (char_u *)0L} SCTX_INIT},
@@ -3228,6 +3236,9 @@ static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
32283236
#if defined(MSWIN) && defined(FEAT_TERMINAL)
32293237
static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
32303238
#endif
3239+
#ifdef FEAT_SYN_HL
3240+
static char *(p_culopt_values[]) = {"line", "number", "both", NULL};
3241+
#endif
32313242

32323243
static void set_options_default(int opt_flags);
32333244
static void set_string_default_esc(char *name, char_u *val, int escape);
@@ -6326,6 +6337,15 @@ did_set_string_option(
63266337
}
63276338

63286339
#ifdef FEAT_SYN_HL
6340+
/* 'cursorlineopt' */
6341+
else if (varp == &curwin->w_p_culopt
6342+
|| gvarp == &curwin->w_allbuf_opt.wo_culopt)
6343+
{
6344+
if (**varp == NUL
6345+
|| check_opt_strings(*varp, p_culopt_values, FALSE) != OK)
6346+
errmsg = e_invarg;
6347+
}
6348+
63296349
/* 'colorcolumn' */
63306350
else if (varp == &curwin->w_p_cc)
63316351
errmsg = check_colorcolumn(curwin);
@@ -10775,6 +10795,7 @@ get_varp(struct vimoption *p)
1077510795
#ifdef FEAT_SYN_HL
1077610796
case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
1077710797
case PV_CUL: return (char_u *)&(curwin->w_p_cul);
10798+
case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt);
1077810799
case PV_CC: return (char_u *)&(curwin->w_p_cc);
1077910800
#endif
1078010801
#ifdef FEAT_DIFF
@@ -11012,6 +11033,7 @@ copy_winopt(winopt_T *from, winopt_T *to)
1101211033
#ifdef FEAT_SYN_HL
1101311034
to->wo_cuc = from->wo_cuc;
1101411035
to->wo_cul = from->wo_cul;
11036+
to->wo_culopt = vim_strsave(from->wo_culopt);
1101511037
to->wo_cc = vim_strsave(from->wo_cc);
1101611038
#endif
1101711039
#ifdef FEAT_DIFF
@@ -11087,6 +11109,7 @@ check_winopt(winopt_T *wop UNUSED)
1108711109
check_string_option(&wop->wo_stl);
1108811110
#endif
1108911111
#ifdef FEAT_SYN_HL
11112+
check_string_option(&wop->wo_culopt);
1109011113
check_string_option(&wop->wo_cc);
1109111114
#endif
1109211115
#ifdef FEAT_CONCEAL
@@ -11132,6 +11155,7 @@ clear_winopt(winopt_T *wop UNUSED)
1113211155
clear_string_option(&wop->wo_stl);
1113311156
#endif
1113411157
#ifdef FEAT_SYN_HL
11158+
clear_string_option(&wop->wo_culopt);
1113511159
clear_string_option(&wop->wo_cc);
1113611160
#endif
1113711161
#ifdef FEAT_CONCEAL

src/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ enum
11611161
#ifdef FEAT_SYN_HL
11621162
, WV_CUC
11631163
, WV_CUL
1164+
, WV_CULOPT
11641165
, WV_CC
11651166
#endif
11661167
#ifdef FEAT_STL_OPT

src/screen.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,7 +3817,7 @@ win_line(
38173817
{
38183818
// Do not show the cursor line when Visual mode is active, because it's
38193819
// not clear what is selected then. Do update w_last_cursorline.
3820-
if (!(wp == curwin && VIsual_active))
3820+
if (!(wp == curwin && VIsual_active) && *wp->w_p_culopt != 'n')
38213821
{
38223822
line_attr = HL_ATTR(HLF_CUL);
38233823
area_highlighting = TRUE;
@@ -4021,6 +4021,7 @@ win_line(
40214021
* TODO: Can we use CursorLine instead of CursorLineNr
40224022
* when CursorLineNr isn't set? */
40234023
if ((wp->w_p_cul || wp->w_p_rnu)
4024+
&& *wp->w_p_culopt != 'l'
40244025
&& lnum == wp->w_cursor.lnum)
40254026
char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
40264027
#endif
@@ -4055,7 +4056,8 @@ win_line(
40554056
{
40564057
char_attr = HL_ATTR(diff_hlf);
40574058
# ifdef FEAT_SYN_HL
4058-
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
4059+
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
4060+
&& *wp->w_p_culopt != 'n')
40594061
char_attr = hl_combine_attr(char_attr,
40604062
HL_ATTR(HLF_CUL));
40614063
# endif
@@ -4117,7 +4119,8 @@ win_line(
41174119
tocol += n_extra;
41184120
#ifdef FEAT_SYN_HL
41194121
/* combine 'showbreak' with 'cursorline' */
4120-
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
4122+
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
4123+
&& *wp->w_p_culopt != 'n')
41214124
char_attr = hl_combine_attr(char_attr,
41224125
HL_ATTR(HLF_CUL));
41234126
#endif
@@ -4212,7 +4215,8 @@ win_line(
42124215
&& n_extra == 0)
42134216
diff_hlf = HLF_CHD; /* changed line */
42144217
line_attr = HL_ATTR(diff_hlf);
4215-
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
4218+
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
4219+
&& *wp->w_p_culopt != 'n')
42164220
line_attr = hl_combine_attr(line_attr, HL_ATTR(HLF_CUL));
42174221
}
42184222
#endif
@@ -5180,7 +5184,8 @@ win_line(
51805184
if (vi_attr == 0 || char_attr != vi_attr)
51815185
{
51825186
char_attr = HL_ATTR(diff_hlf);
5183-
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
5187+
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
5188+
&& *wp->w_p_culopt != 'n')
51845189
char_attr = hl_combine_attr(char_attr,
51855190
HL_ATTR(HLF_CUL));
51865191
}

src/structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ typedef struct
249249
# define w_p_cuc w_onebuf_opt.wo_cuc // 'cursorcolumn'
250250
int wo_cul;
251251
# define w_p_cul w_onebuf_opt.wo_cul // 'cursorline'
252+
char_u *wo_culopt;
253+
# define w_p_culopt w_onebuf_opt.wo_culopt // 'cursorlineopt'
252254
char_u *wo_cc;
253255
# define w_p_cc w_onebuf_opt.wo_cc // 'colorcolumn'
254256
#endif

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ NEW_TESTS = \
9292
test_crypt \
9393
test_cscope \
9494
test_cursor_func \
95+
test_cursorline \
9596
test_curswant \
9697
test_debugger \
9798
test_delete \

src/testdir/gen_opt_test.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ let test_values = {
8282
\ 'completeslash': [['', 'slash', 'backslash'], ['xxx']],
8383
\ 'cryptmethod': [['', 'zip'], ['xxx']],
8484
\ 'cscopequickfix': [['', 's-', 's-,c+,e0'], ['xxx', 's,g,d']],
85+
\ 'cursorlineopt': [['both', 'line', 'number'], ['', 'xxx', 'line,number']],
8586
\ 'debug': [['', 'msg', 'msg', 'beep'], ['xxx']],
8687
\ 'diffopt': [['', 'filler', 'icase,iwhite'], ['xxx', 'algorithm:xxx', 'algorithm:']],
8788
\ 'display': [['', 'lastline', 'lastline,uhex'], ['xxx']],

0 commit comments

Comments
 (0)