15
8
I can use vim -u filename
to use filename
instead of my default .vimrc
. I am using this method when switching user contexts (su
) to use my .vimrc
even though running as superuser.
How can I achieve the same also for the folder which by default is ~/.vim
so that I can point Vim from the command line to an alternative folder?
What I want to achieve
Okay, assume user joe
(HOME=/home/joe
) and user root
(HOME=/root
). User joe
has an alias set for vim
which looks like this (but originally set using the $HOME
variable to make this dynamic):
alias vim='vim -p -N -n -i NONE -u "/home/joe/.vimrc"'
Then user joe
does something along the lines of sudo su -
(but with added magic), resulting in the .bashrc
and other goodies from /home/joe
to be loaded for root
. User root
has now the exact same alias for vim
set as shown above.
The problem is that this .vimrc
is used on various systems and in various scenarios. Often Joe's account is called joe
, but sometimes it'll be something like local.joe
or whatever else, resulting in a different value for $HOME
. So hard coding an absolute path to the ~/.vim
folder doesn't seem to be a good idea. However, in our above scenario user root
doesn't have a folder /root/.vim
which, however, is expected to exist by default via the loaded .vimrc
(/home/joe/.vimrc
).
What I want to achieve - preferably on the command line - is to get Vim to use plugins etc from underneath /home/joe/.vim
when started as root
(assuming the alias
is set as shown - other cases can be ignored). If there is some dynamic method via VimScript, please provide pointers. But using variables such as $HOME
would lead to a catch 22, I think.
you can probably get this done with good old
ln
. like 'mv ~/.vim ~/.vim-whatever && ln -s ~/.vim-whatever ~/.vimthen do the same for
.vimrc`. wrap all that up with some bash alias so you can easily switch one way or the other – jar – 8 years ago