Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For example, for command sudo vim /var/log/errors.log, I want vim to be lanuched with my own user settings instead of root settings. I know I could set up vim for root account, but it is not what I want, for it is likely to be messed up in future update. And also I don't want to change the vim behavior of other accounts.

share|improve this question

3 Answers 3

I could not test, but this may work: sudo HOME=/home/myusername vim /var/log/errors.log

Or in a easier way: sudo HOME=$HOME vim /var/log/errors.log

share|improve this answer
    
It is nice workaround. I met errors:Error detected while processing /home/zane/.vim/bundle/neocomplcache/plugin/neocomplcache.vim: line 37: "sudo vim" and $HOME is not same to /root are detected.Please use sudo.vim plugin instead of sudo command or set always_set_home in sudoers, but it seems ok. –  RNA Jul 13 '12 at 19:20
sudoedit

It's MUCH more secure too.
To use vim (if it's not otherwise your default editor)

(export VISUAL=vim; sudoedit file)

but even better.... set VISUAL and EDITOR in your ~/.bashrc so it is your default editor.

share|improve this answer

You'll need to edit the /etc/sudoers file and potentially those in /etc/sudoers.d/ and remove the env_reset option in the Defaults statements.

Mine looks like this:

Defaults env_reset

Remove, or comment out that line, and sudo will retain your user's environment variables, rather than dump everything and populate with a few specific values.

Of course, see the sudoers man page for more details, and remember to edit the sudoers file with the command visudo (or sudo visudo). visudo checks the sudoers file for errors before it'll let you finalize the editing... if the file is bad or fails whatever checks... you can't 'sudo' anymore, thus the visudo command.

share|improve this answer
    
my /etc/sudoers and /etc/sudoers.d/ don't have that line. I will look at the sudoers man page to see if there is anything relevent. Thanks anyway, –  RNA Jul 15 '12 at 1:08
    
other options to look for are always_set_home and set_home. You may still have issues if vim is building a home path from the invoking user. –  lornix Jul 15 '12 at 1:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.