Delete newline in Vim

derekerdmann picture derekerdmann · Oct 21, 2010 · Viewed 203.6k times · Source

Is there a way to delete the newline at the end of a line in Vim, so that the next line is appended to the current line?

For example:

Evaluator<T>():
    _bestPos(){
}

I'd like to put this all on one line without copying lines and pasting them into the previous one. It seems like I should be able to put my cursor to the end of each line, press a key, and have the next line jump onto the same one the cursor is on.

End result:

Evaluator<T>(): _bestPos(){ }

Is this possible in Vim?

Answer

Xhantar picture Xhantar · Oct 21, 2010

If you are on the first line, pressing (upper case) J will join that line and the next line together, removing the newline. You can also combine this with a count, so pressing 3J will combine all 3 lines together.