set encoding=utf-8
set fileencoding=cp1251
set fileencodings=ut8-8,latin1
set laststatus=2
set statusline=%{(&fileencoding)}

Vim help says that only global value of fileencoding won't for new empty buffers.

Note that 'fileencodings' is not used for a new file, the global value of 'fileencoding' is used instead. You can set it with:
:setglobal fenc=iso-8859-2

But as far as I can see, it works.

Open Vim, open some file (just in case), and then open a new empty buffer (with :enew, :new, or :vnew). Notice the encoding in status line is cp1251.


  • 1
    Uh, the documentation says "fileencodingS" (plural) doesn't work for new files, so if your new file was utf8-8 or latin1 which is what you have in 'fileencodings' then that would be incorrect. Looks like it's working just as described in the docs, no?
    – filbranden
    Jul 29 at 16:30
  • Well, yes. But it is written that "... global value of 'fileencoding' is used". I haven't specified fileencoding by using setglobal. It is specified with regular set...
    – user90726
    Jul 29 at 16:33
  • 1
    See :help local-options: "With :set both the local and global value is changed. With :setlocal only the local value is changed, thus this value is not used when editing a new buffer."
    – filbranden
    Jul 29 at 16:38
  • 2
    If you feel lost then do :verbose setglobal fenc? and see that it was really set by your vimrc.
    – Matt
    Jul 29 at 17:25


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.