vimrc settings for user dont work for root

You did not state a precise question, so for the sake of completeness : If what you want is being able to modify files as root using your user's vim and .vimrc, you can do

sudo -e /path/to/your/file

sudo will use the editor configured in $EDITOR as the current user, to edit a temporary copy of the file that will get copied over when you write the file.

The caveat is that you will not be able to have any edition history between sessions. For example, if you modify /etc/group once, save the changes and quit, and then reopen the file again, you will not be able to undo the modification you did at first.


For Neovim users, you can do what comes next:

  1. If your root user settings for neovim are important, make a backup for those dotfiles.

  2. Create a symbolic link from your default user to /root/.config directory.

    sudo mv /root/.config/nvim /root/.config/nvim.bkp; sudo ln -s $HOME/.config/nvim /root/.config/

Be aware that some plugins may need some files that are not under .config/nvim directory.


root is a user too, when you start vim with root, vim load the root's Home/.vimrc usually it is /root/.vimrc

You can cp or ln -s your user's vimrc to /root if this is a personal desktop machine.

I hope I understood your problem.

Tags:

Vim