1834183 Members
3090 Online
110064 Solutions
New Discussion

vi editor

 
UniRock
Regular Advisor

vi editor

Hi Everybody,

I have big text file with a lot of hashes (#), how can I view all the lines without hash on vi editor?
Where can I find a good in-depth knowledge document on vi?

Thanks,
RKK
8 REPLIES 8
Steven Schweda
Honored Contributor

Re: vi editor

Lines without "#" anywhere on the line?
Lines without "#" in column 1?

> [...] view [...]

View only, or change?

"man grep", look for "-v".

grep -v '#' file > file_nh ; vi -R file_nh

grep -v '^#' file > file_nh ; vi -R file_nh
Shrikant Lavhate
Esteemed Contributor

Re: vi editor

Hi,

For vi documents.... google with vi editor keyword. You will get lots of PDF links for vi editor documents. Few of them:
http://www.eng.hawaii.edu/Tutor/vi.html
http://unixhelp.ed.ac.uk/vi/index.html

-=ShRi=-
Will it remain a personal, if I broadcast it here!
UniRock
Regular Advisor

Re: vi editor

Thnks for quick response,
Actually I want make changes in the uncommented lines of a file through vi editor.

-RKK
Dennis Handly
Acclaimed Contributor

Re: vi editor

>I want make changes in the uncommented lines of a file through vi editor.

Are you talking about editing the lines one by one or some global change all?

For the former, don't edit the lines starting with "#". For the latter, you can use:
:g/^[^#]/s/foo/bar/g
Or:
:v/^#/s/foo/bar/g
UniRock
Regular Advisor

Re: vi editor

Can I do it like, getting all the uncommented lines and removing commented ones temporarily, then making unique changes to all lines (not search & replace)and finally exiting.
The commented lines should be there in the file as before when I open it again.

-RKK
Dennis Handly
Acclaimed Contributor

Re: vi editor

>getting all the uncommented lines and removing commented ones temporarily, then making unique changes to all lines

Is it that hard to just skip to the next uncommented line? :-)

>The commented lines should be there in the file as before

You can't do this in vi. I don't know about vim nor emacs.
Torsten.
Acclaimed Contributor

Re: vi editor

An internet search will give some good results for terms like "code folding" or "fold text" together with "editor".

Some are GUI based editors, but looks like VIM can do it too.

Try it - good luck!

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Ernesto Cappello
Trusted Contributor

Re: vi editor

Hi RKK, this is the command to replace all hashed "#" with nothing in vi

1) ESC
2) :g/#/s///g

the syntax is:
:g/old_text/s//new_text/g

Best regards.
Ernesto