On Thu, Dec 10, 2020 at 2:37 PM A. Wik <awi...@gmail.com> wrote: > > It seems to me that a modeline would be a convenient place to set the > encoding used for a file. However, while it does set 'fenc' > accordingly, the file is not loaded and displayed according to this > setting. > > Bram said reading is tried with each encoding in fencs until one > succeeds. Why not reload the file with the correct encoding once a > modeline with a fenc setting has been read? > > -Albert.
You are against a chicken-and-egg problem here: the modeline can only be interpreted after the file has ben read into a buffer, and that is too late for setting the 'fileencoding'. For a disk file at least, there are the following ways to circumvent that problem: (a) By setting the 'fileencodings' (plural) heuristic to something starting with "ucs-bom,utf-8" without the quotes and in that order, then any Unicode file with BOM, and any UTF-8 file with or without a BOM, will be correctly detected. (A side-effect is that files in 7-bit ASCII will be detected as UTF-8 but this is not a bug: indeed, UTF-8 and US-ASCII represent anything between U+0000 and U+007F identically.) The default setting of "ucs-bom, utf-8,default,latin1" is an example of this method. (b) For other files whose charset you know in advance, see :help ++enc (c) If a file is read by mistake in the wrong encoding, reread it immediately in another (guessed) better charset. You may need to try several times until it looks right. Example, for a Japanese file mistakenly read in Latin1 :e! ++enc=sjis The exclamation mark discards any possible changes and rereads the file "as-is". Best regards, Tony. -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtYy7X4b6GkWCEhSN9eBa34aaKDQsepESWBXczM4kLxog%40mail.gmail.com.