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

How do I join lines without adding spaces between them?

Answer

gJ

Explanation

The gJ command joins the current line with the line below it without inserting any space between them. This contrasts with the standard J command, which adds a space at the join point.

How it works

  • J joins lines and inserts a space (or removes leading whitespace and adds one space)
  • gJ joins lines and preserves them exactly, concatenating the end of the current line with the start of the next line

Example

Given the text:

http://example
.com/path

With the cursor on the first line, pressing gJ results in:

http://example.com/path

Using regular J would have produced http://example .com/path with an unwanted space.

Tips

  • Use 3gJ to join three lines without spaces
  • In visual mode, select multiple lines and press gJ to join them all without spaces
  • Particularly useful when reconstructing URLs, file paths, or long strings split across lines

Next

How do I always access my last yanked text regardless of deletes?