Not reading ~/.vimrc
I have a ~/.vimrc file that vim doesn't seem to be reading. There is a file at /etc/vimrc, and it looks like it is using that one.
My understanding is that the one in the home directory should override this one, shouldn't it?
Update
cat vim_strace | grep .vimrc
stat64("/etc/vimrc", {st_mode=S_IFREG|0644, st_size=1438, ...}) = 0
open("/etc/vimrc", O_RDONLY|O_LARGEFILE) = 3
stat64("/etc/vimrc", {st_mode=S_IFREG|0644, st_size=1438, ...}) = 0
stat64("/root/.vimrc", {st_mode=S_IFREG|0644, st_size=35, ...}) = 0
open("/root/.vimrc", O_RDONLY|O_LARGEFILE) = 3
stat64("/root/.vimrc", {st_mode=S_IFREG|0644, st_size=35, ...}) = 0
Once you've loaded vim, :scriptnames
will tell you exactly what Vim read.
For me, it starts like this:
1: /Applications/MacVim.app/Contents/Resources/vim/vimrc
2: ~/.vimrc
3: /Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim
4: /Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/synload.vim
5: /Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/syncolor.vim
IF you want to check where a particular setting is being set, use "verbose set". For example, :verbose set background
tells me:
background=light
Last set from ~/.vimrc
so I know that my setting in ~/.vimrc is being read, and that none of the later files is clobbering it.
if you're on linux and want to know if vim is accessing your ~/.vimrc on startup you can launch it with strace:
strace -o vim_strace vim
then quit vim. Open the vim_strace file and search for "vimrc" in the file. you should find a line like that
stat64("/home/youruser/.vimrc", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
which mean that at least vim sees the file.
If anyone happen upon this issue while using neovim you should know (before you start pulling off your hair) that the .vimrc
file is loaded from ~/.config/nvim/init.vim
.
mkdir -p ~/.config/nvim; ln -s ~/.vimrc ~/.config/nvim/init.vim
I had this problem and just added the following to the file ~/.bash_profile
:
alias vim="vim -S ~/.vimrc"
In case anyone else runs across this issue, and like me realizes .vimrc
wasn't read because of sudo, try using sudo -E
. It retains your environment for the command, and $HOME
will point to your own home dir. Note this may not work in environments where /home
is mounted with rootsquash.