I've upgraded vim and now it's unhappy about some UTF-8 values in my .vimrc
.
This lead me to the question -- when vim reads .vimrc
, what encoding does it assume the file has? I.e. what's fileencoding
then?
It is whatever you define with :scriptencoding
. It should be the first line in you .vimrc
file, e.g.:
scriptencoding utf-8
set number
set ...
However, as per the Help for :scriptencoding
, if you set the 'encoding' option in your vimrc, :scriptencoding
must be placed after that.
Be aware that some options (listchars
for example) only accept single width values.
Edit: Yeah, Vim is weird. encoding
is for the editor itself, fileencoding
is for the buffer and scriptencoding
is for Vim scripts.
~/,vimrc
showing how to use scriptencoding
scriptencoding
)
As hinted at in the help files (:help scriptencoding
), if you do not use scriptencoding
, vim does no conversion, effectively assuming the script is in the encoding of the 'encoding'
option. This is very often utf-8
, occasionally latin1
. Other encodings are possible. Generally you want to use
scriptencoding utf-8
when your script file contains non-ascii characters and is encoding in utf-8. If you use only 7-bit ascii characters, it is unnecessary.
'fileencoding'
applies to the current buffer, not scripts. When opening a file, vim tries to guess the encoding from the option 'fileencodings'
.
~/,vimrc
showing how to use scriptencoding