Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ddc_vim/deps.ts>op.fileencodings

Dark deno-powered completion framework for neovim/Vim
Go to Latest
variable op.fileencodings
import { op } from "https://deno.land/x/ddc_vim@v4.3.0/deps.ts";
const { fileencodings } = op;

This is a list of character encodings considered when starting to edit an existing file. When a file is read, Vim tries to use the first mentioned character encoding. If an error is detected, the next one in the list is tried. When an encoding is found that works, 'fileencoding' is set to it. If all fail, 'fileencoding' is set to an empty string, which means the value of 'encoding' is used. WARNING: Conversion can cause loss of information! When 'encoding' is "utf-8" (or one of the other Unicode variants) conversion is most likely done in a way that the reverse conversion results in the same text. When 'encoding' is not "utf-8" some non-ASCII characters may be lost! You can use the ++bad argument to specify what is done with characters that can't be converted. For an empty file or a file with only ASCII characters most encodings will work and the first entry of 'fileencodings' will be used (except "ucs-bom", which requires the BOM to be present). If you prefer another encoding use an BufReadPost autocommand event to test if your preferred encoding is to be used. Example:

au BufReadPost * if search('\S', 'w') == 0 |
        \ set fenc=iso-2022-jp | endif

This sets 'fileencoding' to "iso-2022-jp" if the file does not contain non-blank characters. When the ++enc argument is used then the value of 'fileencodings' is not used. 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

This means that a non-existing file may get a different encoding than an empty file. The special value "ucs-bom" can be used to check for a Unicode BOM (Byte Order Mark) at the start of the file. It must not be preceded by "utf-8" or another Unicode encoding for this to work properly. An entry for an 8-bit encoding (e.g., "latin1") should be the last, because Vim cannot detect an error, thus the encoding is always accepted. The special value "default" can be used for the encoding from the environment. On MS-Windows this is the system encoding. Otherwise this is the default value for 'encoding'. It is useful when 'encoding' is set to "utf-8" and your environment uses a non-latin1 encoding, such as Russian. When 'encoding' is "utf-8" and a file contains an illegal byte sequence it won't be recognized as UTF-8. You can use the 8g8 command to find the illegal byte sequence. WRONG VALUES: WHAT'S WRONG: latin1,utf-8 "latin1" will always be used utf-8,ucs-bom,latin1 BOM won't be recognized in an utf-8 file cp1250,latin1 "cp1250" will always be used If 'fileencodings' is empty, 'fileencoding' is not modified. See 'fileencoding' for the possible values. Setting this option does not have an effect until the next time a file is read.

(default: "ucs-bom", "ucs-bom,utf-8,default,latin1" when 'encoding' is set to a Unicode value)

type

GlobalOption<string>