Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a column of words:

text
text 
text
text
text

and I am searching for a vim command that will produce:

text text text text text

A macro will work of course, but is there something simpler for this purpose?

share|improve this question
    
Can't you just replace all newlines (\n or \r\n depending on your OS) with spaces? –  terdon Mar 15 '13 at 18:48
add comment

1 Answer

up vote 4 down vote accepted

A macro would work, yes, but it's probably not the most efficient method.

How about a simple substitution:

:%s/\n/ <-- whitespace!

Or simply a "join":

5J

edit

Not knowing what your file looks like, it's difficult to propose a definitive answer. The substitution assumes that the buffer only contains the lines in your example (the % means "whole buffer") while the join assumes those lines are somehow located in a sea of text and uses an absolute count for more precision.

The J normal mode command, like its sister the :join Ex command, can work on a range/selection so it is entirely possible to select visually those lines and hit J:

V<down><down><down><down>J
v4jJ
5VJ
etc.
share|improve this answer
    
"join" did the trick, but I selected the lines in the visual mode using "V" and then simply pressed "J". It would be cool if you added this to your answer, I'll accept it anyway. :) Thanks! –  tomislav-maric Mar 15 '13 at 18:52
    
Haha, I actually thought about adding this solution, but I didn't know the structure of your file so I went with a specific solution, 5J. –  romainl Mar 15 '13 at 19:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.