\%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 2

  1. As all Ex-commands :s is linewise.

  2. While executing :s you're in Normal mode.

  3. If %\V is there then the command is restricted to the Visual mode used last time.

  • 1
    When 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.
    – Quasímodo
    Commented 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).
    – Matt
    Commented Feb 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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.