How to change file encoding to utf-8 via vim?

There are a few ways to achieve that, here is for a single file:

 

vi filename.php
:set bomb
:set fileencoding=utf-8
:wq

 

This way is a bit more automated:

vi --run-command=':set bomb, :set fileencoding=utf-8' filename.php"

 

And here is a way for various files:

vim +"set bomb | set fileencoding=utf-8 | wq" $(find . -type f -name *.php)

 

that will also work:

find . -type f -name *.php | xargs vim +"argdo set bomb | set fileencoding=utf-8 | w"

 

Enjoy!

You cannot comment on this entry