Wednesday, April 21, 2010

Changing Line Endings with VI

dos2unix is an easy and popular way to change a file from DOS line endings to Unix line endings. But it isn't foolproof...

When dos2unix doesn't seem to get all the line endings, within VI or VIM or GVIM, try:

where ^M means ctrl-V ctrl-M

or try
:set fileformat=unix

Note, for those who don't know how to use VI, there are tons or resources online, but a quick crash course (maybe I'll do more in another post): Typing vi, vim, or gvim will typically launch a vi-like editor. They all work by typing a colon (:) to do special commands like save, quit, and much more. To begin typing, you have to tell it to go into insert mode by simply typing "i" for insert (or "a" for append to end of line or "o" for new line then insert). It seems complicated, and it is, but you get used to it and then it is super powerful. Use :x to save and quit when done.

No comments:

Post a Comment