Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VI: How to add a prefix to every line? (such as # or //)

Status
Not open for further replies.

no_mad

Full Member level 5
Joined
Dec 10, 2004
Messages
271
Helped
30
Reputation
60
Reaction score
11
Trophy points
1,298
Location
Naboo
Activity points
2,489
Hi,

Any idea how to do this in VI or VIM.
Is it possible?

Thanks
 

Hi,

Do a regular expression search and replace to replace the start of line (^) with the prefix. Like this:

:%s/^/\/\//g

or

:%s/^/#/g

Regards,
Chris
 

    no_mad

    Points: 2
    Helpful Answer Positive Rating
What does the "%" in the command mean?
--
Amr Ali
 

amraldo said:
What does the "%" in the command mean?
That's the range over which you want to search. In this case, % means global so that all the lines in the file will be affected.

Regards,
Chris
 

Hi Chris,

What if i want to insert # or // to specific number of line?
Means, from line no. 20 to line no. 30

Thanks.
 

Then there is no need for the "g" flag I guess.
--
Amr Ali
 

Hi Chris,

What if i want to insert # or // to specific number of line?
Means, from line no. 20 to line no. 30

Thanks.
I guess it will be like this
:n,ms/^/#
or :n,ms/^\/\/\

where n is the number of the starting line while m is the number of the ending line
--
Amr Ali
 

no_mad said:
What if i want to insert # or // to specific number of line?
Means, from line no. 20 to line no. 30
Then you just change the range specifier. Something like this:
:20,30s/^/#/

If you're using VIM, you can also select the lines in visual mode by typing V and using the arrows to highlight some lines. Then, when you type : to start the search command, the range will automatically be inserted. Just continue typing s/^/#/ to complete the command.

Regards,
Chris
 

I found this quick reference card for vi @ **broken link removed**
--
Amr Ali
 

    no_mad

    Points: 2
    Helpful Answer Positive Rating
Yes, i got it.

Highlight the lines, then type this command
:'<,'>s/^/#/g

It works. Thanks for your help.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top