1847264 Members
4158 Online
110263 Solutions
New Discussion

Re: Vi question

 
Hunki
Super Advisor

Vi question

Situation :
-------------
While editing in vi I most often face a situation when I have to do a shift-J to join lines .

Question:
----------
How can I determine which lines need to be joined instead of scrolling and looking over these lines within a long file.

7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: Vi question

Since you haven't defined what conditions define the need to join lines then other than using "The Force" how is anyone supposed to answer this question?
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: Vi question

Shalom,

If there is some criteria for joining lines, you may be able to write a shell script that reads from the original file and creates a second.

There must be some data that a machine can identify, otherwise your current methodology is all you have.

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
Geoff Wild
Honored Contributor

Re: Vi question

The real question is - how did the lines get disjoined in the first place?

Solve that, then you don't need to write a clever script to fix this...

Bottom line - you will have to go through the entire file...

You could do a

:set nu

in vi to see line numbers - that way you can scroll a page at a time.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Steve Post
Trusted Contributor

Re: Vi question

I bet this is what you are looking for. I sure was for a number of years.

OK Let's call your file "myfile.txt." Let's have our formated file called "myfile.formated."

1. cat myfile.txt | sed G | adjust -m72 > myfile.formated
2. vi myfile.formated.
3. :g/^$/de
4. :wq!

Is this what you were looking for?

thingy ......explanation about it.

cat myfile.txt ....spit out the text.
sed G ....double space the file.
adjust -m72 ......WRAP that text when it gets to column 72. (Just like in typing class).

:g/^$/de ......
: ......ed mode
g ......for all lines
/^$/ ......where it is a blank line
de ......delete that line

:wq! ....... Write, Quit, and I really mean it.

Now file myfile.formated is probably what you wanted. Do a man page on adjust for more details.

Now what if you want it to be 200 characters wide and in 3 columns? Oh I think it would be time for perl.
spex
Honored Contributor

Re: Vi question

Hunki,

What criteria are you using to decide which lines should be joined together?

PCS
Michael D. Zorn
Regular Advisor

Re: Vi question

If it's really a text file (not a program source file), you can use the 'adjust'.

I set up a macro in '.exrc' like this:

map ^P {!}adjust -m72

With text on the screen, put the cursor anywhere in the paragraph, type 'CTRL-p' and the whole paragraph adjusts.

Starting at the bottom, hold down ctrl-p, and it will adjust paragraphs all the way to the top.

I'm curious about the "... most often face ...", which makes it sound like that's your most-used operation. What sort of text is it? Regular text, source code, data in text, ...?
Steve Post
Trusted Contributor

Re: Vi question

I don't know about the author here, but "most often face" for me is that I'm typing a document, then I need to make it pretty to printout.

Since I can created documents 4 to 5 times faster in vi than in MS word, I try type in vi first.

Can you imagine keeping your fingers on the keyboard? Never looking for the mouse? Performing a 2000 mouse click operation with 10 keystrokes? VI: the ugly and extremely useful program.

OH OK....at least it is for me. I've been using it since 1987.