Since Vim and NeoVIM defaults to UTF-8, does it make any sense to specify the same option explicitly in vimrc? set encoding="utf-8"

1 Answer 1


It would be set encoding=utf-8, no quotes. set encoding="utf-8" would be an error because "utf-8" would be considered a comment, thus it would be the same as set encoding=.

Vim does not actually default 'encoding' to UTF-8. It defaults to latin1, but will change based on the locale of your environment.

However, since changing 'encoding' at runtime is dangerous (as in, it can cause a crash -- see below), Neovim decided to only support encoding=utf-8. This vastly simplifies the code, since now everything is working with UTF-8 internally, and only has to encode/decode when interfacing with the outside world (saving files in specific encodings, converting input from the locale's encoding, etc.).

IMHO, it's a good idea to always put set encoding=utf-8 in your vimrc. It automatically enables saner encoding detection settings for 'fileencodings' and supports any characters that you'll need to store.

The crash example I gave in 2009 when I suggested changing Vim's default value for 'encoding':

vim -u NONE --cmd 'set enc=utf8 list' -c 'let &lcs="nbsp:".nr2char("8215")'
:put =nr2char("160")
:set enc=latin1
  • What about "vim --help"? That's probably terminal settings that need changing but I only managed to output help contents with all language specific characters cut out. For example 'ŻÓŁTY' => 'TY'
    – Sharak
    Commented Jan 26, 2019 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.