bling
bling

Reputation: 1161

Vim, delete whitespace between 2 lines

given the following:

{
    int a = 123;
    int b = 456;
}

i want to change it to:

{
    int a = 123;int b = 456;
}

if i was using a regular text editor, i would go to the 2nd line, then Home, Shift+Up,Shift+End,Delete

what's vim way of doing this? it should work with any amount of whitespace between line 1 and line 2.

Upvotes: 8

Views: 2842

Answers (1)

lbonn
lbonn

Reputation: 2599

Try the J command. It joins two lines (applied on the first one). If you want to join two lines, separated by several empty lines easily, you can also select the lines between the two in visual mode (V) and then apply J.

However, that command inserts one space between joined lines (in most cases...).

For your requirements, you can use the variant gJ which does not insert (or remove) any space between the lines.

Upvotes: 18

Related Questions