write in utf-8

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

write in utf-8

Ben Thomas-2
Hi,

Is there a way to always force a :write in utf-8 encoding?

Currently, I do

:set fenc=utf-8

before :write but I was wondering if there is something I could add in
my vimrc_

Currently I have

set encoding=utf-8
set fileencodings=ucs-bon,utf-8,latin1

in my vimrc_ which works fine, but if a file is read in latin1, it is
written in latin1...

Thank you,
Ben.
Reply | Threaded
Open this post in threaded view
|

Re: write in utf-8

adah
Ben Thomas wrote:

> Hi,
>
> Is there a way to always force a :write in utf-8 encoding?
>
> Currently, I do
>
> :set fenc=utf-8
>
> before :write but I was wondering if there is something I could add in
> my vimrc_
>
> Currently I have
>
> set encoding=utf-8
> set fileencodings=ucs-bon,utf-8,latin1
>
> in my vimrc_ which works fine, but if a file is read in latin1, it is
> written in latin1...

If you really want to surprise yourself by converting existing files to
UTF-8 without any prompt, add this to your _vimrc:

  au BufWritePre * setlocal fenc=utf-8

Best regards,

Yongwei