Problem with vim when logged in as root
Solution 1
I guess the reason is that your home directory ~
is changed, where contains vim configuration file .vimrc
.
Normally ~
is /root
if you login as root, and is /home/YOURNAME
if you login as YOURNAME.
Solution 2
Maybe you are using vi
to try to start VIM which will not use /etc/vimrc
.
If that is the case, you have two options:
- Use
vim
- Modify
/etc/profile.d/vim.sh
to setvi
as an alias for all users not only for users with auid
>=100
Solution 3
Which vimrc
are you talking about? I don't use/know vim
, but in many cases rc
files have two kinds of "incarnation": a system-wide rc
-file under /etc
that dictates the system defaults for the application and user-wide rc
-files under the user homedirs, where users set their own settings, that override the defaults from the system-wide configuration file.
Meanwhile, there is sudo
, that runs a program as another user (usually root
, maybe, like su
, it allows you to impersonate users other than root
).
As you're running vim
through sudo
, my guess is that you're expecting ~/.vimrc
to be something that it isn't. Either that, or you don't understand what is sudo
doing when you invoke it.
If it really is ~/.vimrc
, then it's not "not working", it's actually working quite well, the issue is that there's probably no ~root/.vimrc
, or it exists with different settings than these you were expecting.
Solution 4
This appears a result of introducing the additional hard-coded "default" vimrc in the newer versions of vim as /usr/share/vim/vimXY/defaults.vim
.
https://github.com/vim/vim/issues/2917#issuecomment-389203845
Until this is fixed, I see the only work-around in creating per-user ~/.vimrc
files (including /root/.vimrc
).
George Eracleous
Updated on September 18, 2022Comments
-
George Eracleous over 1 year
When I login as root or edit a file by
sudo
mode all of the options in my/etc/vimrc
are not working (e.g. highlight line-number etc.)-
Admin about 12 yearsDoes user
root
have avimrc
? -
Admin about 12 yearsi config at /etc/vimrc
-
Admin about 12 yearsWhat does
:echo $VIM
(invim
) tell you? (According to my understanding of:help system-vimrc
, the globalvimrc
is expected to be$VIM/vimrc
) -
Admin about 12 years$VIM is /usr/share/vim
-
Admin about 12 yearsYou could try placing a copy of your
vimrc
in/usr/share/vim/
(while I do not understand why/etc/vimrc
is read at all whenvim
is started by a normal user) -
Admin about 12 yearsSome distros set up
/usr/share/vim/vimrc
as a symlink to/etc/vim/vimrc
.
-
-
George Eracleous about 12 yearsi'm config option in /etc/vimrc.