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

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


Another way:

ggVGJ

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


Ah, I found the answer.

:1,$join

Works like a charm.

EDIT: As pointed out in the comment:

:%join   -or-    :%j

...removes the range.


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.