Vi substitution question

Vi substitution question

Post by Shailende » Sun, 18 Jun 2000 04:00:00



Hello all,

I often read/modify source code which has been written
using Windows editors. I use Vi as my editor. Windows
editors leave carriage return character instead
of new line characters, which Vi shows as ^M

I would like to replace them with new line character
using Vi command mode. I have tried all possible
substitution/regular expressions but haven't been able
to achieve that task. How can it be done?

Thanks
Shailender

 
 
 

Vi substitution question

Post by Christian Kratze » Sun, 18 Jun 2000 04:00:00


Hi,


> Hello all,
> I often read/modify source code which has been written
> using Windows editors. I use Vi as my editor. Windows
> editors leave carriage return character instead
> of new line characters, which Vi shows as ^M
> I would like to replace them with new line character
> using Vi command mode. I have tried all possible
> substitution/regular expressions but haven't been able
> to achieve that task. How can it be done?

do not replace them. Delete them. Microsoft uses ascii(13) and ascii(10)
on line ends. Unix uses ascii(10) only.

you can delete the ^M with a simple command line

        tr -d\015 < file.in > file.out

\015 is ascii 13 (15 octal)

Greetings
Christian

--

Christian Kratzer                               http://www.toplink.net/
Phone:  +49 7032 2701-0
Fax:    +49 7032 2701-19        FreeBSD spoken here!

 
 
 

Vi substitution question

Post by Ken Pizzi » Mon, 19 Jun 2000 04:00:00



> I use Vi as my editor. Windows
>editors leave carriage return character instead
>of new line characters, which Vi shows as ^M

>I would like to replace them with new line character
>using Vi command mode.

:%s/^M$//

(Enter the ^M with Control-V Control-M, not ^ and M.)

                --Ken Pizzini

 
 
 

Vi substitution question

Post by Shailende » Mon, 19 Jun 2000 04:00:00


Thanks!


> > I use Vi as my editor. Windows
> >editors leave carriage return character instead
> >of new line characters, which Vi shows as ^M

> >I would like to replace them with new line character
> >using Vi command mode.

> :%s/^M$//

> (Enter the ^M with Control-V Control-M, not ^ and M.)

>                 --Ken Pizzini

 
 
 

1. vi substitution question

I'm using vi to write a TeX file, and I need to turn the word item into
\item.  The command I thought should work was:

1,$ s/item/\item/g

It says it substituted them, but it really didn't.  I {\em think}
(ooops, I've been TeXing too much!) what's happening is the '\'
character has some special meaning that I'm not aware of and vi is
simply substituting 'item' for 'item' (ie- the '\' is lost somehow)

Could someone help me out on this?

In the spirit of the FAQ, please email me; since this is kind of a basic
question, I won't bother summarizing(sp?) responses unless someone
specifically asks me to.  

Thanks!
 -peter

2. Help - Slackware - CDROM - TVGA

3. Text Substitution in Vi Editor.

4. How can I start OpenWindows with the desktop included?

5. vi substitution - need help with expression

6. dual line modems

7. Help! How do I suppress vi tab substitution?

8. AHA2940 PCI SCSI driver...

9. substitutions in VI editor

10. substitutions in vi

11. Text Substitution in Vi Editor.

12. what is the vi edit (substitution) command to delete all blank lines

13. substitution on entire buffer in vi