LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-04-2004, 09:37 PM   #1
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Question ^M and vim


Hello all.

I was editing a file in various programs such as gedit, kword, vim, emacs, and using cat to view the file to see which worked best and what differences between them. Now when I use vim to view the file, "^M" appears at the end of every line where it didn't before I opened it up in the other programs. The strange thing is that using cat, gedit, kword, etc. to view the file doesn't show these characters. What is this, and why is it only in vim?

Thanks.
 
Old 08-04-2004, 10:06 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
It's a carriage return and probably means you're editing a DOS file. To be honest, sometimes it opens with '[dos format] and sometimes it shows the ^M. Not sure what the deal is there. Anyway - you can strip them with a ':%s/<ctrl-v><enter>$//'.

I might be wrong about the details, but point is, vim just shows superfluous returns and they can be stripped. Or left, if you wish.
 
Old 08-04-2004, 11:16 PM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally posted by digiot
:%s/<ctrl-v><enter>$//'.
Actually this would work as well and much easier at the command mode in vi or vim:

:1,$ s/^M//

And to get the ^ just do the ctrl-v and simply an M
 
Old 08-04-2004, 11:25 PM   #4
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Original Poster
Rep: Reputation: 30
Ah, ok. I had forgotten that the original file was sent to me from someone running Windows before I did all the editing in those programs. So I'm confused... are the ^M's part of the file or not? I don't think they are since cat doesn't show them, but if they aren't part of the file how can I strip something that isn't there . Sorry for my lack of understanding, I just don't know how these DOS files in Linux work. Thanks again.
 
Old 08-04-2004, 11:34 PM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
They're there but they're non-printable characters. Vim's showing a control-character representation of them and the others aren't. Try 'cat -v <file>' and you'll see them there, too. xxd <file> shows '0d0a' whereas a *nix file will show '0a' at line endings. (I think.) That's what's 'really' in the file. Just indicates cr-lf vs. lf to mark line endings.
 
Old 08-04-2004, 11:36 PM   #6
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Original Poster
Rep: Reputation: 30
Ok, that makes sense. Thanks again for the info.

EDIT:
Hmm, I'm having trouble stripping those. I was trying to type the ^M and <ctrl-v> gives me a "^" with the cursor on top of it. If I type "m" or <shift-m> it just replaced that "^" with that letter.

EDIT 2:
Nevermind, <ctrl-v> <enter> worked. Thanks.

Last edited by jrdioko; 08-04-2004 at 11:43 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
encryption with Vim (vim -x) mikshaw Linux - Software 2 03-07-2007 09:00 AM
vim bluetwist Debian 2 08-01-2005 08:43 PM
Vim and C++ Dartelin Programming 4 09-16-2004 09:30 AM
VIM help bender_pondie Linux - Software 3 08-01-2003 10:58 AM
Better looking VIM? the_styler Linux - Newbie 5 04-04-2003 07:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration