Vim Trick: Use your user’s .vimrc even when you sudo

I have a huuuuuuuge .vimrc configuration file. When I need to edit an /etc file, for example, I use sudo.

Watch Free Movies

like: sudo vim /etc/passwd

But, using sudo I loose my user’s ~/.vimrc file, as vim uses it’s default.

I have googled for a solution for having my user’s .vimrc file even when I use sudo, and so, I have found this solution:

$ sudo vim -u ~/.vimrc /etc/some_file

The -u arguments asks vim to load the file following it.

To make things easier, I have created this usefull function:

  • svim () { sudo vim -u /home/razvan/.vimrc @$ } ;

To make this function permanent, add the line to your ~/.bashrc file.

Now, instead of using that long sudo command, just type svim /path/to/file.

Scroll to Top