I'm re-learning Vim, and now I'm building my own ~/.vim/.vimrc file. Yes, it is store under the .vim/ folder, which is created by MacOSX after I updated to Big Sur. What I want is simply this

set belloff=all

when I put this line in ~/.vimrc it works, while in ~/.vim/.vimrc it's not. So my questions are:

  1. What's the first file Vim read so it knows Oh, so Mr. .vimrc your home is at $HOME(or ~)?
  2. Which file should I change so that Vim will say Ok, I should read Mr. .vimrc from ~/.vim/?

1. For the first question

According to the help menu (see :help $MYVIMRC), vim will look for a user vimrc in specific places. It look first for ~/.vimrc and then for ~/.vim/vimrc. Vim stops searching after the first one found (that's why we need to remove ~/.vimrc).

Vim will set automatically the $MYVIMRC environment variable to the location of the vimrc used.

2. For the second question:

  1. Put your vimrc content in ~/.vim/vimrc (you must remove the ., so vimrc instead of .vimrc)

  2. Remove ~/.vimrc

  • Thank you Fabrice! Might I ask you that what is $MYVIMRC? Who will read it and what is it for? – job_start Jan 3 at 15:15
  • 2
    You're welcome! I am not totally sure (I'm still learning myself), $MYVIMRC is one of the global variables Vim use to start. It contains the location of the actual vimrc (you can try :echo $MYVIMRC to see it or :e $MYVIMRC to open it) What I know is that it isn't a environnement variable of the system (no need trying to change it this way) but I think you can change it inside of vim (I have seen a post here) – Fabrice Hategekimana Jan 3 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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