On Tuesday, April 18, 2023 at 5:58:25 PM UTC+2 Yee Cheng Chin wrote:
No, please *don't* set fileencoding, encoding, or fileformats in your vimrc
at all. That's not where those settings should go and in fact you should
rarely need to set these settings. The default works just fine. I recommend
reading the documentation on what each one does. Online snippets like
StackOverflow and great for addressing specific needs but they are not good
for setting up a vimrc cohesively.
Setting 'encoding' etc. in the vimrc _may_ be a good idea if they aren't
yet set to utf-8 (this usually means on Windows but it might happen on any
weirdly set system). The snippet below, somewhere near the top of your
vimrc, will make sure that Vim, on any system, uses utf-8 internally, which
will allow it to process files in any encoding (for some unusual ones you
may have to tell it what to use in the :new or :edit command for the file,
see ":help ++enc"). This snippet is written using non-vim9 syntax; I've
liberally added comments (take them or leave them, they make of course no
difference to the snippet's working) to make it easier to understand.
" save the keyboard locale if defaulted to the same as 'encoding'
if == ""
let =
endif
" if 'encoding' is not already some Unicode Transfer Format,
" use UTF-8
if !~? '^u'
set enc=utf-8
endif
" The following ('fencs' with a final s) defines the heuristic to use
" when reading a file, to determine its encoding.
" It is a comma-separated list with no intervening spaces.
" It may be varied as follows:
" * ucs-bom should come first; it will recognize Unicode files having
" a BOM (byte-order mark ; "encoding mark" would be a better
" designation) i.e. a U+FEFF codepoint as the very first character.
" * utf-8 should come next ; it will recognize files encoded in UTF-8
" even without BOM.
" * default will use (if possible) the system default locale
" ($LC_CTYPE or equivalent) as set on your computer. If it is an 8-bit
" encoding it will always be accepted.
" * latin1 (or some other predefined 8-bit encoding) should come last,
" especially if the default encoding is not before it or is not 8-bit. It
will
" catch whatever has not yet been caught by whatever is to its left.
set fencs=ucs-bom,utf-8,default,latin1
" The following ('fenc' without the final s, defined globally) defines
" what to use when creating a new file from scratch.
" One advantage of UTF-8 is that files containing only characters
" in the range 0x00 to 0x7F are represented identically in UTF-8
" and in (7-bit) us-ascii. You might prefer some other default: YMMV.
setg fenc=utf-8
Best regards,
Tony.
--
--
You received this message from the "vim_mac" 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_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to vim_mac+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_mac/28aa43dd-9c8f-4e93-9d02-4e5f2dd69594n%40googlegroups.com.