3

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
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
username_4567
  • 4,737
  • 12
  • 56
  • 92
  • Maybe duplicate of [In Vim, what is the simplest way to join all lines in a file into a single line?](http://stackoverflow.com/questions/391710/in-vim-what-is-the-simplest-way-to-join-all-lines-in-a-file-into-a-single-line) – bimlas May 23 '14 at 05:57
  • @BimbaLaszlo the desired output of the question is not a single line. – Kent May 23 '14 at 09:10
  • @Kent yeah, i can see now, but should rewrite the example int he question to `a \n b \n c \n d` -> `ab \n cd` – bimlas May 23 '14 at 11:04
  • @BimbaLaszlo not exactly. he is doing `xargs -n3` – Kent May 23 '14 at 11:07

3 Answers3

11

And another one:

:%norm JJ

See :help :normal.

romainl
  • 186,200
  • 21
  • 280
  • 313
4

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

ohyecloudy
  • 191
  • 7
1
: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.)

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324