Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: delete all blank space until next non-blank character

Tags:

vim

vi

Say I have the following code:

<p>
    Hello
</p>

And I want to make it

<p>Hello</p>

I would like to put the cursor in normal mode at the end of line 1, so on the ' > ' and have a command to delete all spaces until the next character. The closest I can think of is the motion

d/Hello

which deletes everything until Hello but the issue is that it deletes also the character under the cursor (the ' > ') so I end up with

<pHello
</p>

How would you do that?

like image 710
gws Avatar asked Jan 13 '12 12:01

gws


People also ask

How do I delete a space in vi?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.


1 Answers

One way when you won't need to repeat this action many times.

JxJx

Explanation:

J           # Join current line with next one but substitute end of line with a space.
x           # Remove the space.
Jx          # Repeat same process for last line.
like image 196
Birei Avatar answered Oct 21 '22 19:10

Birei