Monday, February 14, 2011

Vim Usage: Convert to Unix format from dos format

When a dos format text file is edited by *nix system, a "^M" character will be added at the end of each line. This is because there is a difference between line break of dos system and that of *nix system.

If you are vim user, you certainly will open the file with vim. You probably will see some information that ""dos.txt" [dos] 55L, 33C". [dos] means you are editing a dos format file. If you see [mac] instead of [dos], it means it is created under mac environment.

Some time, you will get an error about wrong interpreter if you wrote a shell under windows and then execute under *nix system. One possible reason is due to "^M" character, thus you need to delete all this character. There are many methods to do so. Previously, I introduced a unix tool to convert dos file to unix file using dos2unix (read this post). This time, I use vim since it is built-in *nix already.


In command mode
 : set ff
[this will file format of current file]
 : set fileformat=unix

No comments:

Post a Comment