zhijie
zhijie

Reputation: 642

In VIM, how to join next line when current line does not end with space

In vim , what command should be used if I wanna join next line when current line does not end with space.

original text:

aaaa(space)
bbbbx
cccc

after command :

aaaa(space)
bbbbxcccc

:g/^.*(!\s)$/,/./-j gives error

I am not familiar with VI. Thanks!

Upvotes: 1

Views: 720

Answers (1)

Dave Halter
Dave Halter

Reputation: 16325

Regex is a little bit special in VI. You have to escape some operations. Therefore use \v at the beginning of your pattern, if you want normal behaviour.

The following pattern does what you want:

:%s/\v( \n)|\n/\1/g

As you can see there is a %s in front of it. Which is similar to sed. Instead of % you can also use 2,3 which are lines, where the regex should be executed.

Upvotes: 1

Related Questions