Skip to content

Commit a04f457

Browse files
committed
patch 9.0.0457: substitute prompt does not highlight an empty match
Problem: Substitute prompt does not highlight an empty match. Solution: Highlight at least one character.
1 parent b1842de commit a04f457

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/ex_cmds.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,6 +4308,10 @@ ex_substitute(exarg_T *eap)
43084308
- regmatch.startpos[0].lnum;
43094309
search_match_endcol = regmatch.endpos[0].col
43104310
+ len_change;
4311+
if (search_match_lines == 0
4312+
&& search_match_endcol == 0)
4313+
// highlight at least one character for /^/
4314+
search_match_endcol = 1;
43114315
highlight_match = TRUE;
43124316

43134317
update_topline();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
|o+1&#ffffff0|n+0&&|e| @56
2+
|t|w|o| @56
3+
|t|h|r|e@1| @54
4+
|~+0#4040ff13&| @58
5+
|~| @58
6+
|~| @58
7+
|~| @58
8+
|r+0#00e0003&|e|p|l|a|c|e| |w|i|t|h| @1|.@2|/|a|/|q|/|l|/|^|E|/|^|Y|)|?> +0#0000000&@10|1|,|1| @10|A|l@1|

src/testdir/test_substitute.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
source shared.vim
44
source check.vim
5+
source screendump.vim
56

67
func Test_multiline_subst()
78
enew!
@@ -684,6 +685,21 @@ func Test_sub_cmd_9()
684685
bw!
685686
endfunc
686687

688+
func Test_sub_highlight_zero_match()
689+
CheckRunVimInTerminal
690+
691+
let lines =<< trim END
692+
call setline(1, ['one', 'two', 'three'])
693+
END
694+
call writefile(lines, 'XscriptSubHighlight', 'D')
695+
let buf = RunVimInTerminal('-S XscriptSubHighlight', #{rows: 8, cols: 60})
696+
call term_sendkeys(buf, ":%s/^/ /c\<CR>")
697+
call VerifyScreenDump(buf, 'Test_sub_highlight_zer_match_1', {})
698+
699+
call term_sendkeys(buf, "\<Esc>")
700+
call StopVimInTerminal(buf)
701+
endfunc
702+
687703
func Test_nocatch_sub_failure_handling()
688704
" normal error results in all replacements
689705
func Foo()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ static char *(features[]) =
703703

704704
static int included_patches[] =
705705
{ /* Add new patch number below this line */
706+
/**/
707+
457,
706708
/**/
707709
456,
708710
/**/

0 commit comments

Comments
 (0)