username_4567
username_4567

Reputation: 4903

Run vim command on every line in a vim buffer

I want to JJ on every line in the current vim buffer. As I have very huge file, it is not possible to manually run on every line. How can I tell vim to do this for me? Basically I have a file which has data in single column. I want to convert it to three columns

a
b
c

to:

a b c

Upvotes: 5

Views: 5422

Answers (3)

romainl
romainl

Reputation: 196466

And another one:

:%norm JJ

See :help :normal.

Upvotes: 12

Ingo Karkat
Ingo Karkat

Reputation: 172510

:g/^/join

joins consecutive lines (1+2, 3+4, and so on...) in the entire buffer. You can also supply a [range] to the :global command, which here is only used for its intelligent line handling; the ^ regular expression pattern matches any line.

To join three consecutive lines, use either

:g/^/.,.+2join

or

:g/^/join|join

(The former may give an error if the total amount of lines isn't divisible by 3; the latter avoids that.)

Upvotes: 3

ohyecloudy
ohyecloudy

Reputation: 191

Use Macro and Normal mode command.

qqJJq

Recoding JJ commands to q

uu

Define q macro. undo all.

:%norm! @q

apply q to entire document.

PS : I'm not good at english

Upvotes: 4

Related Questions