Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .