Batch file encoding conversion with Vim

Publication date
03/27/2007
Categories
, ,
$ ex filename '+set fenc=utf-8' '+x'

It's basically the same to opening the file using vim, change its encoding (set fenc=utf-8), save (if needed) and quit (x).

The advantage over using other methods (like iconv) is that vim will try to detect automatically the current file encoding.

So, for example you can change all you .html files to Unicode at the same time:

$ find -name '*.html' -exec ex {} '+set fenc=utf-8' '+x' \;

1 comment

  1. Ahmed

    05/09/2008 | #

    Thanks, works perfectly! I've been looking for a way like this to convert a bunch of files to UTF-8 all at once.

Comment this post

Fields marked with * are required.

*
It won't be made public. If you have a gravatar it will be displayed.
*