Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vi and substitution

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
I'm looking at substitution in vi. (More specifically gvim)

Two questions:

1) Can you use the pipe function?

e.g. %s/stert/start | %s/ende/end

I get the error "Trailing characters" when trying this.


2) How do you use substitute in the "/" character

e.g. %s/the/</the>

I get the error &quot;Trailing characters&quot; when trying this also.

Thanks in advance,

Chris
 
AFAIK, you can't use the pipe character in %s in vi
The / needs to be 'escaped' - that is, a backslash needs to be put in front of it e.g. %s/the/<\/the>

HTH Dickie Bird (:)-)))
 
Alternatively, you don't have to use / as the separator in substitution commands, eg:

%s:the:</the>:

would work too.

Chris
 
Thanks very much.

If you can't use a pipe character. Is there anyway of doing more than one substitute in one line?

Thanks

Chris
 
If your using vi why care so much to do more than one substitution at a time?

If you have to then write a macro (a)

map a :%s/stert/start/g^M:%s/ende/end/g^M

or use the commands available to the shell (b) such as

%!sed 's/stert/start/g;s/ende/end/g'

The % is your global address [address[,address] and ^M is the key combination of control-V and control-M. Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Cheers,

I just wanted to know if it was possible in vi.

Thanks,

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top