2

I store my .vimrc in my dotfiles repository located at ~/dotfiles/.vimrc, which I want to manage with Git using vim-fugitive. I have symlinks from my home directory to my dotfiles, i.e. ~/.vimrc -> ~/dotfiles/.vimrc.

I two problems with this:

  • I can't do something like :edit $MYVIMRC, change something and run :Gcommit, as fugitive does not follow symbolic links. Via the symlink my ~/dotfiles/.vimrc opens when running the edit command, but fugitive commands are not available.
  • In my .vimrc I define a number of autocommands that do use $MYVIMRC - some of them do no longer work, because they also have their troubles with the symlink.

Both problems could be easily fixed if I could change the value of $MYVIMRC, but I can't figure out how to do that. How can I change the value of $MYVIMRC?

I understand that I can also just ignore $MYVIMRC, i.e. replace it in all autocommands and not use it to edit my .vimrc, but this seems not like a good solution.

0

1 Answer 1

5

let command in vimL allows you to assign a value to a variable. A variable may be a environment variable, or a register or an option.

 :let $MYVIMRC=value

This command sets the value to $MYVIMRC. You can put this in .vimrc.

Example:

 :let $MYVIMRC=C:\Users\acer\Desktop
1
  • 1
    Setting let $MYVIMRC="/home/username/dotfiles/.vimrc" in my .vimrc works as long as I don't open the symlinks. I am surprised that I could just set it like a normal variable, given its unusual variable name. Embarassing... Thanks :-)
    – cbaumhardt
    May 26, 2016 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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