You are not logged in.

#1 2013-04-13 11:45:01

jrussell
Member
From: Cape Town, South Africa
Registered: 2012-08-16
Posts: 510

[solved] confusion about vim and its config files

Hi, Im getting really confused with vim and its /etc/vimrc config, and the per user ~/.vimrc.

On one of my PC's I have an untouched /etc/vimrc and a /home/jason/.vimrc which has:

syntax on

now, on that same PC, if I run

vim .vimrc

"syntax on" in green and yellow as expected, and if I run

sudo vim .vimrc

I also see
"syntax on" in green and yellow, but surely this is opening it as root?
*Edit
Even though there is no .vimrc in /root, and the system-wide /etc/vimrc is untouched/blank


On another PC I also have an untoched /etc/vimrc, and a /home/jason/.vimrc which has:

syntax on

Aswell, and:

vim .vimrc

has "syntax on" in green and yellow as expected, but this time:

sudo vim .vimrc

Has no colour?


I cant explain this, any ideas?

*Edit
To clarify, both PC's have an untouched /etc/vimrc and there is no /root/.vimrc file on either PC

Last edited by jrussell (2013-04-14 10:21:42)


bitcoin: 1G62YGRFkMDwhGr5T5YGovfsxLx44eZo7U

Offline

#2 2013-04-13 13:12:02

siriusb
Member
From: Hungary
Registered: 2010-01-01
Posts: 422

Re: [solved] confusion about vim and its config files

The configuration files in /etc are for system-wide settings. These are the default settings if not overridden by a user's own settings in their home directory.

So running vim as your regular user will use the settings from your home directory.
What does sudo? From man sudo

sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy.

 
So if you didn't specify any setting in the home folder of the user you want to run vim as, and you don't have anything in /etc/vimrc, vim won't apply any custom settings.

Offline

#3 2013-04-13 14:43:25

jrussell
Member
From: Cape Town, South Africa
Registered: 2012-08-16
Posts: 510

Re: [solved] confusion about vim and its config files

siriusb wrote:

The configuration files in /etc are for system-wide settings. These are the default settings if not overridden by a user's own settings in their home directory.

So running vim as your regular user will use the settings from your home directory.
What does sudo? From man sudo

sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy.

 
So if you didn't specify any setting in the home folder of the user you want to run vim as, and you don't have anything in /etc/vimrc, vim won't apply any custom settings.

I understand all of that, but on both my PC's I have a clean/untouched config /etc/vimrc, and both /root/.vimrc files do not exist, so howcome on one PC I get colour with sudo vim...., and on the other I dont?


bitcoin: 1G62YGRFkMDwhGr5T5YGovfsxLx44eZo7U

Offline

#4 2013-04-13 15:20:40

Xyne
Forum Fellow
Registered: 2008-08-03
Posts: 6,965
Website

Re: [solved] confusion about vim and its config files

Check the output of

sudo echo $HOME

on both systems. If they are different, make sure that you don't have any aliases or environment variables that affect sudo's behavior.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#5 2013-04-13 17:45:53

jrussell
Member
From: Cape Town, South Africa
Registered: 2012-08-16
Posts: 510

Re: [solved] confusion about vim and its config files

Xyne wrote:

Check the output of

sudo echo $HOME

on both systems. If they are different, make sure that you don't have any aliases or environment variables that affect sudo's behavior.

on both PC's it returns the home directory of the logged in user, both users are in the sudoers file with the same setup, (the usernames are not the same)


bitcoin: 1G62YGRFkMDwhGr5T5YGovfsxLx44eZo7U

Offline

#6 2013-04-13 18:50:04

siriusb
Member
From: Hungary
Registered: 2010-01-01
Posts: 422

Re: [solved] confusion about vim and its config files

I think in one case environmental variables are passed with sudo, and in the other not.
You can check, if you open a root shell with su -, so it will load the root env vars. From this shell run vim.

Offline

#7 2013-04-13 20:29:11

jrussell
Member
From: Cape Town, South Africa
Registered: 2012-08-16
Posts: 510

Re: [solved] confusion about vim and its config files

siriusb wrote:

I think in one case environmental variables are passed with sudo, and in the other not.
You can check, if you open a root shell with su -, so it will load the root env vars. From this shell run vim.

If I run

su

and login as root and run vim on both PC's I get no colour, which is expected


bitcoin: 1G62YGRFkMDwhGr5T5YGovfsxLx44eZo7U

Offline

#8 2013-04-13 20:37:28

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [solved] confusion about vim and its config files

Have you altered sudoers on the machine that has syntax working using elevated priviledges?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#9 2013-04-14 10:21:24

jrussell
Member
From: Cape Town, South Africa
Registered: 2012-08-16
Posts: 510

Re: [solved] confusion about vim and its config files

jasonwryan wrote:

Have you altered sudoers on the machine that has syntax working using elevated priviledges?

Got it.
I had added

Defaults env_keep += "HOME"

to the bottom of the sudoes file on the PC that was keeping my options across sudo.


bitcoin: 1G62YGRFkMDwhGr5T5YGovfsxLx44eZo7U

Offline

Board footer

Powered by FluxBB