[vim/vim] System vimrc (/etc/vimrc) isn't read if Vim is compiled with VIMRCLOC and VIMRUNTIMEDIR set (#8878)

12 views
Skip to first unread message

zdohnal

unread,
Sep 16, 2021, 7:25:37 AMSep 16
to vim/vim, Subscribed

Describe the bug
System vimrc (/etc/vimrc) isn't read during startup, if Vim is compiled with VIMRCLOC=/etc and VIMRUNTIMEDIR=/usr/share/vim/vim82. I can see in :version output:

   system vimrc file: "$VIM/vimrc"
   fall-back for $VIM: "/etc"
   f-b for $VIMRUNTIME: "/usr/share/vim/vim82"

so I expect /etc/vimrc will be read (according src/INSTALL file), but from gdb debugging:

Breakpoint 2, do_source (fname=fname@entry=0x682628 "$VIM/vimrc", check_other=check_other@entry=0, 
    is_vimrc=is_vimrc@entry=0, ret_sid=ret_sid@entry=0x0) at scriptfile.c
1134	    p = expand_env_save(fname);
(gdb) s
..
..
..
vim_getenv (mustfree=0x7fffffffdde4, name=0x749520 "VIM") at misc1.c:1680
1680	    p = mch_getenv(name);
(gdb) n
1681	    if (p != NULL && *p == NUL)	    // empty is the same as not set
(gdb) p p
$2 = (char_u *) 0x721a64 "/usr/share/vim"

So the $VIM seems to be taken from helpfile option:

:set helpfile
  helpfile=/usr/share/vim/vim82/doc/help.txt

and /usr/share/vim/vimrc doesn't exist on the system.

Using helpfile value makes sense according :help $VIM (since VIMRUNTIMEDIR is set during compilation, so it doesn't contain env variable, so it is usable according help), but src/INSTALL file says:

Unix: PUTTING vimrc IN /etc

Some Linux distributions prefer to put the global vimrc file in /etc, and the 
Vim runtime files in /usr.  This can be done with:
  ./configure --prefix=/usr
  make VIMRCLOC=/etc VIMRUNTIMEDIR=/usr/share/vim MAKE="make -e"

To Reproduce
$ ./configure --enable-gui=no --prefix=/usr
$ make VIMRCLOC=/etc VIMRUNTIMEDIR=/usr/share/vim/vim82 MAKE="make -e"
$ ./src/vim -c "scriptnames"
(no /etc/vimrc in scriptnames...)

Expected behavior
Vim reads /etc/vimrc at startup

Environment (please complete the following information):

  • Vim version [8.2.3441]
  • OS: Fedora

Additional context
Currently in Fedora we have a downstream patch which patches os_unix.h (changing $VIM/vimrc to /etc/vimrc), but one test from test suite, Test_exrc from test_startup.vim fails because of it, so I'm trying to figure out how to get rid of the downstream patch, but still use /etc/vimrc. So if the behavior which I reported is expected, I would be grateful for suggestions how else to set up Vim to read /etc/vimrc.

Thank you in advance for looking into this!

Zdenek


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Bram Moolenaar

unread,
Sep 16, 2021, 3:35:49 PMSep 16
to vim/vim, Subscribed

I probably don't want to change the current behavior, many people depend on it.
Perhaps making the docs more clear can help.
Using a system-wide vimrc file often annoys users, it is often used for too many admin preferences.
Also, putting files right under /etc is becoming less common, most systems use another (sub) directory.

zdohnal

unread,
Sep 17, 2021, 2:24:33 AMSep 17
to vim/vim, Subscribed

I probably don't want to change the current behavior, many people depend on it.
Perhaps making the docs more clear can help.

That would be great - the current INSTALL is a bit misleading. Additionally, it could mention the solution from Debian for such cases.

Using a system-wide vimrc file often annoys users, it is often used for too many admin preferences.
Also, putting files right under /etc is becoming less common, most systems use another (sub) directory.

I see - moving the files into subdir could help for VIMRCLOC only builds, but once VIMRUNTIMEDIR is set, VIMRUNTIMEDIR will get the upper hand... so I will not move the files into subdir for now and I will adopt Debian solution - creating symlink /usr/share/vim/vimrc, which will point to /etc/vimrc - I'll look into it, thx!

Bram Moolenaar

unread,
Sep 19, 2021, 3:41:58 PMSep 19
to vim/vim, Subscribed


> > I probably don't want to change the current behavior, many people
> > depend on it. Perhaps making the docs more clear can help.
>
> That would be great - the current INSTALL is a bit misleading.
> Additionally, it could mention the solution from Debian for such
> cases.

The details are at ":help startup". Can you suggest changes there?


> > Using a system-wide vimrc file often annoys users, it is often used
> > for too many admin preferences.
> > Also, putting files right under /etc is becoming less common, most
> > systems use another (sub) directory.
>
> I see - moving the files into subdir could help for VIMRCLOC only
> builds, but once VIMRUNTIMEDIR is set, VIMRUNTIMEDIR will get the
> upper hand... so I will not move the files into subdir for now and I
> will adopt Debian solution - creating symlink /usr/share/vim/vimrc,
> which will point to /etc/vimrc - I'll look into it, thx!

I'll leave reviewing that to people using that.

--
I wonder how much deeper the ocean would be without sponges.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

zdohnal

unread,
Sep 23, 2021, 2:57:38 AMSep 23
to vim/vim, Subscribed

@brammool

The details are at ":help startup". Can you suggest changes there?

I meant the changes should be done in src/INSTALL file since it contains misleading information which let users think they can setup Vim to read from /etc only by setting compilation variables.
IMO :help startup is fine.

Reply all
Reply to author
Forward
0 new messages