In Vim, what is the simplest way to join all lines in a file into a single line?

You can do it in three fewer keystrokes:

:1,$j

isn't ed grand?


Ah, I found the answer.

:1,$join

Works like a charm.

EDIT: As pointed out in the comment:

:%join   -or-    :%j

...removes the range.


Another way:

ggVGJ

"ggVG" visually selects all lines, and "J" joins them.


You can do it with 3 keystrokes starting from normal mode:

:%j
  • : enters command mode
  • % refers to all lines in the file
  • j executes the join command

Now it seems that this adds a space between the lines. I am not sure if you want this.

Tags:

Windows

Vim