Bug 1643311 - /etc/vimrc sets fileencodings overriding any command line settings
Summary: /etc/vimrc sets fileencodings overriding any command line settings
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: vim
Version: 29
Hardware: Unspecified
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Karsten Hopp
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-10-25 22:31 UTC by Wojciech Pilorz
Modified: 2019-07-20 02:33 UTC (History)
3 users (show)

Fixed In Version: vim-8.1.1713-1.fc30
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-07-20 02:33:45 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
patch do /etc/vimrc (357 bytes, patch)
2018-10-25 22:31 UTC, Wojciech Pilorz
no flags Details | Diff

Description Wojciech Pilorz 2018-10-25 22:31:13 UTC
Created attachment 1497580 [details]
patch do /etc/vimrc

Description of problem:
File /etc/vimrc start with the following:
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=ucs-bom,utf-8,latin1
endif

If this settings is inappropriate, there is no way to change it
from command line (or script) starting vim/gvim

This makes starting gvim for editing files in 8-bit encodings like cp-1250, cp-852, etc, cumbersome


Version-Release number of selected component (if applicable):
any

How reproducible:
Any file in 8-bit encoding will be opened as if it were in latin1 


Steps to Reproduce:
1. Generate test file
mkdir /dev/shm/vimtest
chdir /dev/shm/vimtest
echo zażółć gęślą jaźń | iconv -f utf-8 -t cp1250 > testfile.txt


2. Open test file with gvim:
2A)
gvim -R testfile.txt
or,
2B)
gvim -R --cmd 'set fencs=cp1250' testfile.txt

3. on Gvim prompt:
:echo &fileencoding

Actual results:
Garbled characters, I am not aware of any method of setting fileencodings from command line, as it gets changed by /etc/vimrc lines 1-3

Expected results:
starting gvim as in 2B) should respect fileencodings value specified on command line

Additional info:

If I enter commands within vim
:set fencs=cp1250
:e!

The file is displayed properly

4. Patch proposal

Please consider replacing first 3 lines in /etc/vimrc with the following:

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   if empty(&fileencodings)
     set fileencodings=ucs-bom,utf-8,latin1
   endif
endif

After that change setting fileencodings from command line via --cmd parameter
seems to work (and 2B displays file correctly).

Comment 1 Zdenek Dohnal 2019-07-08 12:30:01 UTC
Hi Wojciech!

thank you for filing the issue and the patch! Actually we can get the same behavior if I remove the mentioned 'if' statement from vimrc, so I was trying to investigate why that 'if' is even there for (there is no git message about the change, because it was imported even from CVS long time ago...). It seems like it is checking if v:lang variable has utf8 or UTF-8 strings at the end... Karsten, do you have any idea why it is in default /etc/vimrc? Because Vim sets those values automatically if encoding is utf-8.
I can remove this if for now and see if anyone will complain about it...

Comment 2 Karsten Hopp 2019-07-09 11:40:40 UTC
I've added ucs-bom to that line in 2008, the rest is from 2004. I couldn't find any traces where it came from, but I didn't dig very deep. It might have been in the upstream vimrc.example back then.
 vim has changed a lot in the meantime and handles defaults much better. I'd recommend to compare our /etc/vimrc with the current upstream vimrc.example and runtime/defaults.vim and use the upstream vimrc with some of our changes.

Comment 3 Zdenek Dohnal 2019-07-18 12:51:38 UTC
I merged defaults.vim with our vimrc and removed fileencodings settings, because it seems vim sets it co rrectly now. It is fixed in 8.1.1713-1 which will arrive in bodhi in hour or two.

Beware:
vimrc is set as config file, so it will not be replaced automatically, you need to replace it manually.

Comment 4 Fedora Update System 2019-07-18 14:02:18 UTC
FEDORA-2019-c008d1f32c has been submitted as an update to Fedora 30. https://bodhi.fedoraproject.org/updates/FEDORA-2019-c008d1f32c

Comment 5 Fedora Update System 2019-07-19 01:34:42 UTC
vim-8.1.1713-1.fc30 has been pushed to the Fedora 30 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-c008d1f32c

Comment 6 Fedora Update System 2019-07-20 02:33:45 UTC
vim-8.1.1713-1.fc30 has been pushed to the Fedora 30 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.