Learn Vim / How to Join Lines in Vim

How to Join Lines in Vim

The answerPress J — the line below is joined onto the current one with a space managed for you.

Try it on a real buffer

Someone hit Enter mid-sentence. With the cursor on line 1, press J to join line 2 up onto it.

This sentence was accidentally
split across two lines.
And this one is fine.

Canonical solution: J (with cursor on line 1) · par: 1 keystroke (vimgolf rules — every keypress counts).

Why it works

J joins the line below onto the current one, managing the space between them for you. gJ joins without adding a space.

Variations

KeysWhat it does
Jjoin the next line up
3Jjoin three lines
gJjoin without inserting a space

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “Reunited” mission takes about a minute.

Practice free — no signup →

Keep going