[NBLUG/talk] vim fileformat

Kyle Rankin kyle at nblug.org
Mon Sep 11 13:49:12 PDT 2006


On Mon, Sep 11, 2006 at 01:42:27PM -0700, Barry Stump wrote:
> I have some files whose format is mis-detected by vim.  They were
> origionally dos format (lines ending with \r\n) but somewhere along
> the way they had the occasion unix format (\n) line ending added.
> Now, when opening them up in vim, I see all the annoying ^M characters
> because it thinks (incorrectly) that they are unix format.
> 
> I know that I can use
> :set fileformat=dos
> to change the file format, but because of source control, I can't just
> save the file and reload it to see the changes.  How do I get vim to
> change the format and re-process the buffer in place so that the
> display of the ^M characters go away without changing the actual file?
> Alternatively, a vim command line parameter to force it to read the
> file as a certain format would also work, if such a thing exists.
> 
> Anyone know any vim magic that can help?
> 
> -Barry
> 

One way to do this would just be to "repair" the file so that all those
wayward \n lines were \r\n:

perl -pi.bak -e 's/(?<!\r)\n/\r\n/g' filename

-- 
Kyle Rankin
NBLUG President
The North Bay Linux Users Group
http://nblug.org
IRC: greenfly at irc.freenode.net #nblug 
kyle at nblug.org



More information about the talk mailing list