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
Jjoins lines and inserts a space (or removes leading whitespace and adds one space)gJjoins 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
3gJto join three lines without spaces - In visual mode, select multiple lines and press
gJto join them all without spaces - Particularly useful when reconstructing URLs, file paths, or long strings split across lines