vimtricks.wiki Concise Vim tricks, one at a time.

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 V and motions
  • Press J to 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

  • gJ joins 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

Next

How do you yank a single word into a named register?