LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
 
LinkBack Search this Thread
Old 08-04-2004, 10: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, 11:06 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,099

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-05-2004, 12:16 AM   #3
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,093

Rep: Reputation: 111Reputation: 111
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-05-2004, 12:25 AM   #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-05-2004, 12:34 AM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,099

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-05-2004, 12:36 AM   #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-05-2004 at 12:43 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 10:11 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration