9

I performed following command

:'<,'>s/2/digit/g

on the code below manually visually selected:

return _.round(this.getTotalAbs(), 2).toFixed(2);

And it worked as intended

return _.round(this.getTotalAbs(), digit).toFixed(digit);

Now I want to repeat the same substitute command on another code snippet manually selected via visual selection mode, with one keystroke(if possible).

3
  • You can type :'<, and then up arrow. It will show the previous substitute. Are you okay with any mappings?
    – SibiCoder
    Jun 30, 2016 at 14:27
  • @SibiCoder I do not want to create mapping. I want to use native command if available within vim.
    – WitVault
    Jun 30, 2016 at 14:31
  • You'll have to create a mapping if you want a single keystroke.
    – Antony
    Jun 30, 2016 at 15:22

1 Answer 1

15

I think you want to do @: which replays the last ex command.

See :h @:

Note that this command can be called from normal mode and from visual mode. Also in this case it is not useful but you can also prefix it with a count.


Edit In the comments @Antony pointed out an interesting command: :& (:h :&):

  • & can be used in normal mode to repeat the last substitute command without its flags
  • :&& can be used in ex mode to repeat the last substitute command keeping the flags.
2
  • 10
    Or :&& to repeat the last substitution with the same flags.
    – Antony
    Jun 30, 2016 at 15:20
  • @Antony: Cool command I didn't knew it.
    – statox
    Jun 30, 2016 at 15:30

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.