The incsearch
option is very specific to highlight the text that matches a pattern used in a search (which is defined as a /.../
or a ?...?
block.)
When you're using :g/^##1##\n.*/+,/##z##/- y
, it will only highlight the text that matches the first search pattern, /^##1##\n.*/
, which matches the header line and the following line.
(The reason why only the first pattern is showed by incsearch
is a bit complicated... But it boils down to the second pattern is part of the command that :g
executes for each match of the first pattern, so it doesn't get evaluated until :g
starts executing the command for each line that matches the first pattern.)
How come the result are different between yanking/pasting and using incsearch?
This is not unusual at all! In fact, if you search for a pattern, it's not trivial to find a yank or delete command that will act on exactly that region... (Well, there's the gn
motion, but it's somewhat unique in that respect.) For instance, if you use y/pattern/
Vim will not yank the text matching the pattern, but the text in between the current cursor position and the start of the next match for the pattern...
If you want to search (and have incsearch
or hlsearch
highlight) the text in between the ##1##
header and the ##z##
terminator, then use a pattern that will match that block in between:
/^##1##\n\zs\_.\{-}\ze\n##z##$/
But here again, note how having the block highlighted isn't really necessarily helping you yank or delete it... (But, then, look into the gn
motion if you'd like to act on the matches themselves.)