\%V
can be used to restrict match within the visual selection. However, I can't think of a situation when one would not want to do just that in visual mode.
2 Answers
As all Ex-commands
:s
is linewise.While executing
:s
you're in Normal mode.If
%\V
is there then the command is restricted to the Visual mode used last time.
-
1When in visual mode, pressing
:
puts:'<,'>
into the command line, so I don't get point 2. I'm with Tejasvi88: It would be nice if it did:
<,>
instead. Feb 16, 2021 at 11:41 -
@Quasímodo 1. After pressing enter in cmdline-mode you get into Normal mode, see
:h mode-switching
. 2. It actually honours line range, but it's linewise, see (1).– MattFeb 16, 2021 at 12:15
Probably because it can be achieved easily using a keymap.
xnoremap <expr> :s mode()==#'V' ? ':s' : ':s/\%V\%V/<Left><Left><Left><Left>