I'd like to insert a word in multiple lines, is there any command like

:[2,3,5,7,11]s/^/word\ /g

which would insert word at the beginning of line 2, line 3, line 5, line 7 and line 11?

Here, multiple lines are not contiguous.


Performing a substitution on several consecutive lines is pretty easy:

:2,11s/^/word /

but a range can't cover non-consecutive lines.

With a bit of creativity, though, it is entirely possible to work around that "limitation".

Indeed, you can repeat the last substitution with :& or :&& (the former will not preserve the original flags, the latter will) so you can chain substitutions pretty easily:

2s/^/word /|3&|5&|7&|11&

See :help :& and scroll around for :&&.

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.