I had problems several times because the vim encoding was set to latin1 by default, and I did not notice and suggested that it uses utf-8. Now that I have it, I would like to configure vim so that it does everything correctly in all obvious cases and uses utf-8 by default.
What I would like to avoid:
- Forcing a file saved in some other encoding that would work before my changes open as utf-8, which will lead to gibberish.
- Forcing a terminal that does not support multibyte characters (such as Windows XP) to try and display them anyway, resulting in gibberish.
- Interaction with the ability of other programs to read or edit files (I have a (possibly unreasonable) aversion to using the default specification, because I do not understand how likely this will lead to the launch of other programs.)
- Other questions that I don't know enough to guess about (but hopefully you do!)
What I have so far:
if has("multi_byte") if &termencoding == "" let &termencoding = &encoding endif set encoding=utf-8 " better default than latin1 setglobal fileencoding=utf-8 " change default file encoding when writing new files "setglobal bomb " use a BOM when writing new files set fileencodings=ucs-bom,utf-8,latin1 " order to check for encodings when reading files endif
This is taken and slightly modified from the vim wiki . I moved bomb from setglobal fileencoding to my own statement, because otherwise it actually doesn't work. I also commented on this line due to my uncertainty regarding specifications.
What I'm looking for:
- Possible errors to avoid what I missed
- Problems with existing code
- Links to everything already mentioned / already indicated
Ultimately, I would like this to lead to an unnecessary copy / paste fragment that will set vim to utf-8 by default, which will work on different platforms.
EDIT: I marked my own answer as it is accepted at the moment, as far as I can tell, it works fine and takes into account everything that it can reasonably take into account. But it is not set in stone; If you have any new information, feel free to reply!
vim encoding unicode utf-8
Nick Knowlson Mar 29 '11 at 19:02 2011-03-29 19:02
source share