Chances are they are in the file. When you start vim with the file, look at the status line (at the bottom). If there's something like this
"test.txt" [dos]
it means that the file is in DOS format with carriage return/line feed line endings. vim can correctly interpret them, and if you yank a line the line endings go with it. But for the buffer vim doesn't know it's in DOS format, and shows the carriage return as the corresponding control character: ^M (one character, not 2).
By the way, if you want to apply a substitution to a small part of the file, select it (using v or V), and, without pressing ESC/y/x/d/... enter
:s/
The command line should then look like this:
:'<,'>s/
which means that the command will only be applied to the selected text.
When I execute :set list, each line is terminated by a red dollar sign ($). No ^M's in sight.
The file was created in the following way. It is text from an article in a medical journal that I highlighted and copied from Firefox. I then pasted it into an empty Vim buffer and saved it.
I am sure there is something very simple I am missing/screwing up. Please forgive my newbie-ness.
Do you use vim/gvim on windows as editor when doing this or via a terminal session, let's say putty? I guess it is either a setting in gvim or putty if you are sure the file is clear of ^M.
What does the "od" command return, when run on this file ? If you really have DOS end-of-line character sequences, then you'd see "\r\n" in the output, as seen below:
$
$ cat t2
first line
second line
third line
$
$ od -bc t2
0000000 146 151 162 163 164 040 154 151 156 145 015 012 163 145 143 157
f i r s t l i n e \r \n s e c o
0000020 156 144 040 154 151 156 145 015 012 164 150 151 162 144 040 154
n d l i n e \r \n t h i r d l
0000040 151 156 145 015 012
i n e \r \n
0000045
$
$
If your file has the Unix end-of-line character, then the output will show "\n" :
$
$ od -bc t2
0000000 146 151 162 163 164 040 154 151 156 145 012 163 145 143 157 156
f i r s t l i n e \n s e c o n
0000020 144 040 154 151 156 145 012 164 150 151 162 144 040 154 151 156
d l i n e \n t h i r d l i n
0000040 145 012
e \n
0000042
$
$
If your file is huge, you may want to run that command on only a couple of lines at the beginning: