editorconfig / editorconfig-vim

EditorConfig plugin for Vim
http://editorconfig.org
Other
3.14k stars 139 forks source link

Fix &fileencoding changed to utf-8 upon :e #194

Closed h3xx closed 2 years ago

h3xx commented 2 years ago

For some reason, this plugin is causing :e to change the file's encoding option (&fileencoding) to utf-8, overriding whatever it's currently set to.

This doesn't happen upon first opening the file, but only upon re-opening it with :e. Probably because the script executes before

This weird fix works apparently due to some weird vim internal discrepancy between how set enc and let &enc work. Using let seems to also mess with the file's encoding (&fileencoding).

I should mention I was editing a file that did not have any .editorconfig settings applied to it.

Steps to reproduce:

  1. Open and save a file in latin1 mode:
    export LANG=en_US LC_ALL=en_US LC_CTYPE=en_US
    vim foo.txt
    :set fenc=latin1
    :w
  2. Without closing Vim, reload the file:
    :e
  3. Check the file encoding hasn't changed:
    :echo &fenc

&fenc should still be latin1. If it was reset to utf-8 the issue persists.

Closes #145

k-takata commented 2 years ago

I've already created another fix to this issue: #186

h3xx commented 2 years ago

Interesting. I'm also thinking that BOM's in .editorconfig files are such an edgecase that it may not be worth it to support it. (YAGNI)

h3xx commented 2 years ago

Closed in favor of #186, a much more comprehensive fix.

Tested against changes in #186, and it in fact fixes the issue described in this PR.