Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a column of words:


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
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":



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:

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! – tmaric 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .