6

I'm sure this has been asked before, but I haven't had much luck with a search. Is there an easy way to append the next line to the end of the current line?

Example:

this.thing = that
    .getThing();

I am looking for a one-stroke command that turns it into:

this.thing = that.getThing();
eggonlegs
  • 1,824
  • 2
  • 23
  • 34

3 Answers3

13

Shift-J joins the next line with the current one. It removes indentation but usually adds a space, unfortunately.

These commands, except "gJ", insert one space in place of the <EOL> unless there is trailing white space or the next line starts with a ')'. These commands, except "gJ", delete any leading white space on the next line.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
5

Use J which is short for join.

Vim doc copied below

                            *J*
J           Join [count] lines, with a minimum of two lines.
            Remove the indent and insert up to two spaces 
FDinoff
  • 30,689
  • 5
  • 75
  • 96
2

Adding to the other answers, if you want to keep the cursor position you can use a mark:

:nnoremap J mzJ`z
  • mz - add mark to register z
  • J - join as usual
  • `z - go to the mark set
timss
  • 9,982
  • 4
  • 34
  • 56