This is very similar to #2337 but applies to :s. I believe it is a regression introduced after the patch for #2337.
When starting a new substitute none of the text is highlighted as expected. Then enable very magic (\v) and suddenly all text is highlighted. I'd expect this to behave the same way as starting a new substitute.
Steps to reproduce:
$ vim -N -u NONE -c "set hlsearch incsearch" /path/to/file
Then type:
:s/\v
Expected result: nothing is highlighted
Actual result: entire line is highlighted
It's even more obvious when a full buffer substitute is started, in that case the whole buffer is highlighted:
:%s/\v
VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 13 2018 14:59:01)
Included patches: 1-279
Compiled by Arch Linux
Huge version with GTK3 GUI. Features included (+) or not (-):
+acl +extra_search +mouse_netterm +tag_old_static
+arabic +farsi +mouse_sgr -tag_any_white
+autocmd +file_in_path -mouse_sysmouse +tcl/dyn
+autochdir +find_in_path +mouse_urxvt +termguicolors
-autoservername +float +mouse_xterm +terminal
+balloon_eval +folding +multi_byte +terminfo
+balloon_eval_term -footer +multi_lang +termresponse
+browse +fork() -mzscheme +textobjects
++builtin_terms +gettext +netbeans_intg +timers
+byte_offset -hangul_input +num64 +title
+channel +iconv +packages +toolbar
+cindent +insert_expand +path_extra +user_commands
+clientserver +job +perl/dyn +vartabs
+clipboard +jumplist +persistent_undo +vertsplit
+cmdline_compl +keymap +postscript +virtualedit
+cmdline_hist +lambda +printer +visual
+cmdline_info +langmap +profile +visualextra
+comments +libcall +python/dyn +viminfo
+conceal +linebreak +python3/dyn +vreplace
+cryptv +lispindent +quickfix +wildignore
+cscope +listcmds +reltime +wildmenu
+cursorbind +localmap +rightleft +windows
+cursorshape +lua/dyn +ruby/dyn +writebackup
+dialog_con_gui +menu +scrollbind +X11
+diff +mksession +signs -xfontset
+digraphs +modify_fname +smartindent +xim
+dnd +mouse +startuptime -xpm
-ebcdic +mouseshape +statusline +xsmp_interact
+emacs_tags +mouse_dec -sun_workshop +xterm_clipboard
+eval +mouse_gpm +syntax -xterm_save
+ex_extra -mouse_jsbterm +tag_binary
system vimrc file: "/etc/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "/etc/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
defaults file: "$VIMRUNTIME/defaults.vim"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/uuid -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/libdrm -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -pthread -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.28/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -Wl,--as-needed -o vim -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lelf -lnsl -lacl -lattr -lgpm -ldl -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.28/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib -L/usr/lib/perl5/5.28/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lm
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
No, it happens because incsearch did until very recently not highlight patterns for the :s command.
I think we would need a patch like this:
diff --git a/src/ex_getln.c b/src/ex_getln.c index b0da5d80e..d6e53089d 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -562,7 +562,7 @@ may_do_incsearch_highlighting( { next_char = ccline.cmdbuff[skiplen + patlen]; ccline.cmdbuff[skiplen + patlen] = NUL; - if (empty_pattern(ccline.cmdbuff)) + if (empty_pattern(ccline.cmdbuff + skiplen)) set_no_hlsearch(TRUE); ccline.cmdbuff[skiplen + patlen] = next_char; }
With this patch the highlighting doesn't happen anymore, however the cursor will jump to beginning of the line (:s/\v) or the beginning of the buffer (:%s/\v).
however the cursor will jump to beginning of the line (:s/\v) or the beginning of the buffer (:%s/\v).
I might be missing something, but that is how incsearch works. And it did that even before my patch.
Not if search hasn't started yet, and \v isn't really searching for anything, it's a modifier for the rest of the search.
The current behaviour of search / with incsearch and hlsearch
/ " nothing to search, nothing is highlighted and the cursor doesn't move /\ " searches for `\`, moves cursor to next match and highlights it¹ /\v " enables very magic, but has nothing to search therefore nothing is highlighted and the cursor jumps back to starting position.
The behaviour of substitute :s is currently inconsistent with the above.
¹ I find this a bit odd, \ is used to escape the next char \\ is used to search for a literal \. Maybe it shouldn't jump/highlight on this char? I never noticed before as I have mappings that will automatically siwtch to very magic mode on :s/ and /.
The current behaviour of search
/withincsearchandhlsearch
/ " nothing to search, nothing is highlighted and the cursor doesn't move /\ " searches for `\`, moves cursor to next match and highlights it¹ /\v " enables very magic, but has nothing to search therefore nothing is highlighted and the cursor jumps back to starting position.
That is not what I observe:
vim --clean -c ':5' -c':norm! $' -c 'set incsearch hls' eval.c
Note: cursor is on the last char:

Now start a search, type:
\ which happens to be on line 830, column 45And that makes sense, because in a pattern kind of sense, there does not exist the notion of pattern modifier, an empty \v just matches everywhere, which you can see by the christmas like highlighting if you actually search for \v, since it matches everywhere.
v Note: cursor moves one character to the left, which happens to be line 6, column 1
I suppose you meant right. I never realised that it moved a single char to the right. I'm seeing the same as you.
And that makes sense, because in a pattern kind of sense, there does not exist the notion of pattern modifier, an empty \v just matches everywhere, which you can see by the christmas like highlighting if you actually search for \v, since it matches everywhere.
But there is a concept of no pattern, as simply typing / does not move the cursor, why is that different? IMHO, any of \c, \C, \v, \m, \M, \V should behave the same as having no pattern.
With the current behaviour, I will have to disable incsearch for substitutions because with the cursor moving I immediately lose context of what I wanted to replace file wide and I cannot use ^r w to insert the word from under the cursor.
I suppose you meant right
correct.
With the current behaviour, I will have to disable incsearch for substitutions because with the cursor moving I immediately lose context of what I wanted to replace file wide and I cannot use ^r w to insert the word from under the cursor.
Perhaps you need to add <C-T> after typing \V to that the cursor moves back.
Perhaps you need to add
<C-T>after typing\Vto that the cursor moves back.
Unfortunately that then highlights everything again.
Disabling incsearch like this will work.
augroup vimrc-incsearch-highlight autocmd! autocmd CmdlineEnter : :set noincsearch autocmd CmdlineLeave : :set incsearch augroup END
It would be much nicer to have very magic just work the same way as normal search does.
fixed by 8b0d5ce
Closed #3363.
Works as expected now.
Thanks.
Actually this has now introduced #2337 again, i.e. /\v will highlight everything and jump to top of file.
—
All text is highlighted with :call matchadd("IncSearch", '\v'), is this intentional?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.![]()
—