amit
amit

Reputation: 5559

convert vertical text to horizontal text in vim

I want to convert the vertical text in my file to horizontal. like

1  
2  
3    

to

1 2 3

I can do this using the tr command tr '\n' ' ' <file

but I want to do this using vim

Upvotes: 0

Views: 3291

Answers (4)

romainl
romainl

Reputation: 196781

And, just for the fun of it:

:{fromLine},{toLine}!tr '\n' ' '

Upvotes: 2

Anurag Peshne
Anurag Peshne

Reputation: 1547

Another way: By replacing \n with

:{fromLine},{toLine}s/\n/ /g

Upvotes: 1

Birei
Birei

Reputation: 36282

An easy one. Use a range from first line until last one and join them with an space between them:

:0,$join

Upvotes: 3

Marth
Marth

Reputation: 24812

Select the lines and join them with J.

From :h J :

                            *J*
J           Join [count] lines, with a minimum of two lines.
            Remove the indent and insert up to two spaces (see
            below).

                            *v_J*
{Visual}J       Join the highlighted lines, with a minimum of two
            lines.  Remove the indent and insert up to two spaces
            (see below).  {not in Vi}

Upvotes: 3

Related Questions