How do I join all selected lines into one line?
Answer
J (in visual mode)
Explanation
In visual mode, pressing J joins all selected lines into a single line with spaces between them. This is the multi-line version of the normal J command.
How it works
- Select multiple lines with
Vand motions - Press
Jto join them all into one line - A space is added between each joined line
- Leading whitespace is removed from joined lines
Example
part one
part two
part three
Select all three lines with Vjj, press J:
part one part two part three
Tips
gJjoins without adding spaces- This is useful for un-wrapping paragraphs
- Works with any number of selected lines
- The cursor is placed at the first join point