Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim - Append next line to end of current [duplicate]

Tags:

vim

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();
like image 659
eggonlegs Avatar asked May 17 '13 02:05

eggonlegs


2 Answers

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.

like image 140
John Kugelman Avatar answered Oct 08 '22 02:10

John Kugelman


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 
like image 27
FDinoff Avatar answered Oct 08 '22 03:10

FDinoff