Why does Vim add spaces when joining lines?

binOr picture binOr · Oct 16, 2009 · Viewed 10.2k times · Source

I want to unwrap text in Vim. When I join lines I get an additional space between sentences.

Why is that?

Answer

overthink picture overthink · Sep 17, 2012

I have a feeling this is what you really want: gJ

From :h gJ:

gJ          Join [count] lines, with a minimum of two lines.
            Don't insert or remove any spaces.  {not in Vi}

This is handy if you've copied something from a terminal and it's pasted it as a big rectangular block into vim, rather than a single line.

I usually use it in visual mode. Hilight stuff, gJ.