Ramneek Singh Kakkar
Ramneek Singh Kakkar

Reputation: 389

Is there a way to replicate same edit in every line or between marked lines in a Vim?

My file looks like this

a
b
c
d

I would like the output of file to be:

.a(a)
.b(b)
.c(c)
.d(d)

Is there a one liner in vim to do so?

Upvotes: 0

Views: 70

Answers (2)

Moberg
Moberg

Reputation: 5509

You can use the global :g to perform on all lines . the norm command (^[ is escape key inserted with <c-v><esc>):

:g/./norm diwi.^[pa()^[P

But you can also record your modification with q and repeat that with @ as many times as you like or for a range. See :h recording.

qq "do your stuff" q select your lines and run norm @q, for example:

:'<,'>norm @q

or with g:

:g/./norm @q

Upvotes: 1

Peter Rincker
Peter Rincker

Reputation: 45147

You can use a substitution:

:%s/.\+/.&(&)/

.\+ to capture non-empty line. & is the entire match inside the replacement section

Upvotes: 4

Related Questions