& repeats the last :s

But it doesn't repeat with flags, e.g. a global sub:


won't replace in the same way on consecutive lines with &, running :s/"/'/g on the first line here and then & on the second

["first", "second"]
["third", "fourth"]


['first', 'second']
['third", "fourth"]

the global option has been forgotten about when using & on the second line

How can I quickly repeat last substitute command with flags?

(not @: because I may have other commands run after :s)


that is what :&& is for

| improve this answer | |
  • 2
    Remember that if you already accidentally pressed &, it becomes the last substitution and the flags are gone – Liu Sha Nov 29 '18 at 4:09
  • 4
    This is correct, but if you add more info the answer will be better. I propose to guide the reader to the relevant help sections, where this is explained immediately. E.g. :help :&. This may also guide readers to learn about things like the mappings & and g&. – Karl Yngve Lervåg Nov 29 '18 at 8:16
  • 4
    I also think that the answers should be full sentences. – Karl Yngve Lervåg Nov 29 '18 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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