Reputation: 4903
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
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
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