Reputation: 2355
I have the problem with DOS new lines (0d 0a
), which I try to replace in vim
. I believe to make already couple of times before, but now I am really stuck, as vim
does not want to see the character:
When I try to enter it by pressing CTRL
V
and CTRL
M
to run :%s/^M//g
, I see the error:
E486: Pattern not found: ^M
Even when I try to replace it by hex code with :%s/\%x0d//g
, I see the error:
E486: Pattern not found: \%x0d
I, however, can remove/replace other characters, e.g. :%s/\%x61//g
When I try :%s/\n/\r/g
, nothing happens
When I try to remove it in two steps with :%s/\n/XXX/g
followed by :%s/XXX//g
, it goes away. However, in case I use :%s/XXX/\r/g
on the second step, vim inserts 0d 0a
back instead of expected 0a
Therefore, question: is there a way to convert all new lines to 0a
in vim
? Why does hex replacement not work?
Upvotes: 1
Views: 266
Reputation: 5963
See :help 'fileformat'
.
:set ff=unix
:w
should do it.
This is matching newlines, by the way:
:%s/\n/\r/
But it's replacing newlines with newlines, and when you write the buffer vim will use whatever line ending is determined by 'fileformat'.
Upvotes: 2