Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim, delete whitespace between 2 lines

Tags:

vim

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.

like image 901
bling Avatar asked Jan 01 '13 01:01

bling


1 Answers

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.

like image 88
lbonn Avatar answered Oct 01 '22 02:10

lbonn