1848540 Members
7013 Online
104033 Solutions
New Discussion

Re: vi question

 
Mike_Ca Li
Regular Advisor

vi question

Hi:
How to add a blank line in any line containing a string "endif"

eg :

endunstring endfi
will result in
endunstring
endif

Thanks
12 REPLIES 12
Raj D.
Honored Contributor

Re: vi question


Do the following whenever u required ,

keep the cursor at endif position.

Step 1:

Esc
" a yy 1 #itwill yank that line in buf a.

when need to add a blank line with endif

step 2:

keep the cursor there .

Esc " a p # it will paste "endif"

Cheers.
Raj D.
" If u think u can , If u think u cannot , - You are always Right . "
H.Merijn Brand (procura
Honored Contributor

Re: vi question

create an empty line as first line, then

:g/\/1,1co .

then remove the empty line again

if you have a more feature rich vi clone like elvis, you can do

:g/\/s/$/\n/

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Geoff Wild
Honored Contributor

Re: vi question

From vi?

/endif
o
esc

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

Re: vi question

Whoops - Merjin has it - ignore mine - didn't understand the complete question.

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.
H.Merijn Brand (procura
Honored Contributor

Re: vi question

And in fact I even don't, because I answered the question, but didn't look good enough at the example.

Personally I'd use perl for that:

# perl -pi -e's/\s+endif\s*$/\nendif/' file

which will do what you want as an in-line replacement

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Raj D.
Honored Contributor

Re: vi question

OPPS Even i ddint understand the question first.

Well here is the very simple answer :

in vi , do the following , from u are begining of the file , do :

Esc :%s/endif/ /g

This will replace all "endif" by a "blank line"

Cheers ,

Raj D.
-------


" If u think u can , If u think u cannot , - You are always Right . "
Mike_Ca Li
Regular Advisor

Re: vi question

I tried to use
:g/\/s/$/\n/

but I end up with

endifn

at all instances of endif

Raj D.
Honored Contributor

Re: vi question

Hi Mike

Try out my last one and give me feedback pls. Whether it fulfills the purpose..

regards

Raj D.
" If u think u can , If u think u cannot , - You are always Right . "
Mike_Ca Li
Regular Advisor

Re: vi question


Your replace endif with space

How to replace with blank line, control characters?
Mike_Ca Li
Regular Advisor

Re: vi question

:g/endif/s/$/^Mendif/

You get the ^M by depressing and holding the ctrl-V and then the 'm'
Francisco J. Soler
Honored Contributor

Re: vi question

Hi,

You can try with the 'at' character, like this

:%s@endif@^Mendif@

the %s means in whole file.
you can get the ^M like Mike_Ca Li says with CTRL-V and then CTRL-M.

this works for me.

Frank
Linux?. Yes, of course.
Geoff Wild
Honored Contributor

Re: vi question

What about trying sed?

sed -e 's/endif/\nendif/g' yourfile

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.