Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
vim search an replace^M Not working for me.^@
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
josephgrey
n00b
n00b


Joined: 11 Jul 2007
Posts: 14

PostPosted: Sat Dec 13, 2008 3:06 pm    Post subject: vim search an replace^M Not working for me.^@ Reply with quote

I have obtained a file with many "^M" characters where newlines should be.

I've tried
Code:
:s/^M/\n/g


That is --
:s/[control-v][control-m]/\n/g[enter]

vim finds all the ^M characters and replaces them with ^@.
I can replace the ^M with \t and the characters turn into tabs. If I then attempt to turn the \t's to \n's they turn into ^@'s. So, its some kind of problem with substituting the newlines.
I think this worked for me at one time. I must be doing something incorrectly. Could someone help me out?
Back to top
View user's profile Send private message
cwr
Veteran
Veteran


Joined: 17 Dec 2005
Posts: 1969

PostPosted: Sat Dec 13, 2008 4:28 pm    Post subject: Reply with quote

If you're cleaning up a DOS file, one approach is:

:%s/.$//

Will
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Sat Dec 13, 2008 4:53 pm    Post subject: Reply with quote

Code:
:set fileformat=unix
:w

_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
josephgrey
n00b
n00b


Joined: 11 Jul 2007
Posts: 14

PostPosted: Sat Dec 13, 2008 6:19 pm    Post subject: Reply with quote

Both of those commands result in the same thing--^M's turn to ^@'s.

I don't know what the deal is.
Back to top
View user's profile Send private message
ok
Guru
Guru


Joined: 11 Jul 2006
Posts: 390
Location: germany

PostPosted: Sat Dec 13, 2008 10:50 pm    Post subject: Reply with quote

Code:
:s/^M/^M/g

:s/[control-v][control-m]/[control-v][control-m]/g[enter]

works for me, don't ask why..
Back to top
View user's profile Send private message
momofuku
n00b
n00b


Joined: 16 Jan 2007
Posts: 3

PostPosted: Sat Dec 13, 2008 11:10 pm    Post subject: Reply with quote

Instead of [ctrl] + M you should actually press [ctrl] + v + [enter].
OR :%s/\r//g

Hope this helps
Back to top
View user's profile Send private message
yabbadabbadont
Advocate
Advocate


Joined: 14 Mar 2003
Posts: 4791
Location: 2 exits past crazy

PostPosted: Sat Dec 13, 2008 11:19 pm    Post subject: Reply with quote

Code:
emerge dos2unix
dos2unix filename

;)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum