Skip to content

Instantly share code, notes, and snippets.

@sharat
Created December 13, 2012 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharat/4278435 to your computer and use it in GitHub Desktop.
Save sharat/4278435 to your computer and use it in GitHub Desktop.
convert the line endings of multiple files in a directory with the help of vi editor.
#Convert from dos/unix to unix
#To convert from any mixture of CRLF endings and LF-only endings, to LF-only endings:[C 1]
:set hidden #Allow modified buffers to be hidden.
:set ffs=dos #Assume dos line endings (CRLF or LF-only) when reading files.
:args *.c *.h #Specify the files to convert.
:argdo set ff=unix|w #For each argument, set unix file format for the buffer, and write the file.[C 2]
#Convert from dos/unix to dos
#To convert from any mixture of CRLF endings and LF-only endings, to CRLF endings:[C 1]
:set ffs=dos #Assume dos line endings (CRLF or LF-only) when reading files.
:args *.c *.h #Specify the files to convert.
:argdo w #Write each file with CRLF line endings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment