You are not logged in.

#1 2007-10-29 16:52:55

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Vim color scheme when using sudo

Hi

I have a color scheme in vim that I really like and everything works perfect as normal user, but as soon as I start vim with sudo (to edit some configs for example), I get a totally different color scheme that's pretty hard on the eyes. I've (soft)linked .vim .vimrc .viminfo .bashrc .themes .icons and .Xdefaults from /root/ to the ones in my home directory but it wont work...
Does anyone know where this stuff is configured?

Offline

#2 2007-10-29 19:11:18

ramoneur
Member
Registered: 2007-06-04
Posts: 89

Re: Vim color scheme when using sudo

maybe /etc/vimrc ?


A w e s o m e
r
c
h

Offline

#3 2007-10-29 19:31:13

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Vim color scheme when using sudo

That should be read by root and normal users in the same way, doesn't it?

Offline

#4 2007-10-29 20:40:48

ramoneur
Member
Registered: 2007-06-04
Posts: 89

Re: Vim color scheme when using sudo

think so, test it out


A w e s o m e
r
c
h

Offline

#5 2007-10-29 20:48:26

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Vim color scheme when using sudo

I've got a /etc/vimrc and a /etc/virc but none of them has any user-specific rules. All home folders and such are referred with $HOME...
I have no clue how these files could cause a difference between root and others. And as said, all config files from /root/ are linked to the working ones in my home directory, which root should be able to read.

Offline

#6 2007-10-29 20:58:59

awagner
Member
From: Mainz, Germany
Registered: 2007-08-24
Posts: 191

Re: Vim color scheme when using sudo

try to put 'sudoedit' into your sudoers (just that command, no path). Then sudoedit normally should open vim with your user environment but root privileges. (I have put some 0-byte vimrc/gvimrc files into /etc so that they don't mess up my setup, and there's no .vimanything in /root)

Last edited by awagner (2007-10-29 21:01:04)

Offline

#7 2007-10-29 21:27:27

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: Vim color scheme when using sudo

You might also want to try "sudo -E" to preserve your environment...not sure if it will work the way you think though.

Offline

#8 2007-10-29 22:02:47

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Vim color scheme when using sudo

Thanks for the replies smile

When I try to use the "-E" option I get this:

sudo -E vim
Password:
sudo: sorry, you are not allowed to preserve the environment

I've got full sudo privileges (ALL=(ALL) ALL).

And I tried adding "sudoedit" in /etc/sudoers through visudo but wherever I place it (defaults line, alias line, privilege specification line) I get a syntax error complaint...

Offline

#9 2007-10-29 22:32:38

awagner
Member
From: Mainz, Germany
Registered: 2007-08-24
Posts: 191

Re: Vim color scheme when using sudo

Ramses de Norre wrote:

And I tried adding "sudoedit" in /etc/sudoers through visudo but wherever I place it (defaults line, alias line, privilege specification line) I get a syntax error complaint...

I have something along the lines of:

MyUsername    ALL = (ALL)   PASSWD: /usr/sbin/visudo, /bin/echo, sudoedit

Offline

#10 2007-10-29 22:35:31

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Vim color scheme when using sudo

This is allowed by visudo:

username  ALL=(ALL) ALL,sudoedit

But it doesn't fix the color scheme problem...

I appreciate your input though!

Last edited by Ramses de Norre (2007-10-29 22:35:44)

Offline

#11 2007-10-29 23:02:04

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Vim color scheme when using sudo

I found that when I add the "sudoedit" option, I can edit files through sudo -e filename.
It's done by copying the edited files to a temp file, editing that file as regular user and then moving that file back to the original destination. The editor used is defined by setting the EDITOR env variable.

I'll use this method if I don't find a better option smile

Offline

#12 2007-10-29 23:23:19

awagner
Member
From: Mainz, Germany
Registered: 2007-08-24
Posts: 191

Re: Vim color scheme when using sudo

sorry, I didn't see your last posting.
But what you have described is what I have been after. Actually sudoedit filename should be doing that same thing.

Offline

#13 2007-10-29 23:31:59

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Vim color scheme when using sudo

Ow, nice smile
Thanks for the help, I'll use this if I can't find a way to make vim act normal.

Offline

#14 2009-07-27 14:53:11

Chiil
Member
Registered: 2009-07-27
Posts: 12

Re: Vim color scheme when using sudo

I don't know if your issue is still open, but here is the solution. vim takes certain settings from the color settings that you use in your console. If you enter the root console via 'su', you'll see that the colors are different. What you can do is copy your .bashrc file, or parts of it, to /root/ and then vi will show the same colors.

Offline

#15 2012-10-03 16:45:43

thisiskun
Member
Registered: 2012-10-03
Posts: 1

Re: Vim color scheme when using sudo

sudo visudo, and add this

Defaults  !env_reset

this work well for me.

Offline

#16 2012-10-03 17:33:27

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

Re: Vim color scheme when using sudo

thisiskun, please don't necrobump https://wiki.archlinux.org/index.php/Fo … Bumping.22

The information you posted is included in the wiki page...


Closing


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB