Operating System - HP-UX
1845752 Members
4266 Online
110249 Solutions
New Discussion

Re: how to combine two lines into 1 long line in vi?

 
SOLVED
Go to solution
Hanry Zhou
Super Advisor

how to combine two lines into 1 long line in vi?

I used to know it, but now I forget about it.


Thanks,
none
9 REPLIES 9
Christian Tremblay
Trusted Contributor

Re: how to combine two lines into 1 long line in vi?

$ will take you to the end of the line then
uppercase J (join) will join the line with the next one.

Chris
A. Clay Stephenson
Acclaimed Contributor

Re: how to combine two lines into 1 long line in vi?

Go to the end of the first line and enter .
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: how to combine two lines into 1 long line in vi?

Hi Hanry:

Position the cursor on the line that you want to join the following line with, and type "J".

Regards!

...JRF...

Hanry Zhou
Super Advisor

Re: how to combine two lines into 1 long line in vi?

Thanks all, it works.

But, after I type "J", there is still a empty character between two lines. Are there any way to automatically combine these two lines without manually removing that empty character?
none
Steven E. Protter
Exalted Contributor

Re: how to combine two lines into 1 long line in vi?

Shalom Hanry,

Shift-J has always worked for me.

Hit escape key once to change modes if that fails to work.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Tommy_6
Regular Advisor
Solution

Re: how to combine two lines into 1 long line in vi?

When using the "Shift-J" command, the only way the lines will combine is if the bottom line starts with a ")". This is straight from the man pages for vi

J Join the current line with the next one, supplying appropriate whitespace: one space between words, two spaces after a period, and no spaces at all if the first character of the next line is a closing parenthesis ()). A preceding count causes the specified number of lines to be joined, instead of just two.

I do not know of any other way to do what you are requesting. Hope this helps!
Dennis Handly
Acclaimed Contributor

Re: how to combine two lines into 1 long line in vi?

If you read ex(1), you'll see that ":j!" will ignore special whitespace processing.

I suppose you could use "map" to make it a keystroke?
Al Langen_1
Advisor

Re: how to combine two lines into 1 long line in vi?

Upper case J. Anywhere on the line. Not sure who wrote the man page that states that the next line must start with a left parenthesis. Simply not true.

Ctrl-J does not join lines.

Alfred

Tommy_6
Regular Advisor

Re: how to combine two lines into 1 long line in vi?

Alfred,
Let me clarify. To prevent a whitespace from appearing when doing a Join, the following line must contain a ")". You are correct that the Shift-J may be used anywhere, but it will also put a whitespace between the two. Hanry is looking for a way to prevent the whitespace from appearing.