Not reading ~/.vimrc

Viewed 74913

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
15 Answers

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 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

Stumbled on this post and non of the suggestions worked for me. Some useful things not mentioned here:

  1. vim --version should give you some useful info including the startup files. (Mine listed "virc" in several places (not vimrc)
  2. If your vim isn't really vim then perhaps it is looking for ~/.exrc instead of .vimrc (Mine looks for some system vircs, then some users vircs and then $HOME/.exrc)
  3. If your file (whichever one it is) has DOS line endings it may cause errors

... so even though I've got a real vim, it's looking for "virc"

Check if $VIMINIT has been set. It may prevent reading your ~/.vimrc. See :help VIMINIT:

 c. Four places are searched for initializations.  The first that exists
    is used, the others are ignored.  [...]
    -  The environment variable VIMINIT [...]

For me unsetting VIMINIT did the trick, my ~/.vimrc is now read.

After checking scriptnames and verbose as suggested above, I noticed that my setting was indeed being loaded, but being overridden by another plugin, thus giving the impression that it was not reading/loading the .vimrc.

If this happens to you and you want to override a specific setting from a plugin, without completely eliminating all the other good things that come from that plugin, you can create a config file to load after the plugin is loaded, by creating a file in ~/.vim/after/<path>/<plugin_name>. For reference, see this other question.

I had the same problem with vim 8.1.3741 on Kubuntu 20.04

It seems the problem was that the ~$/.vimrc file was starting with a long comment starting with " and went over 2 lines (autobreak) The vim_strace showed input 133 and wrote the comment out but not the command under it. Removing the comment worked. Thanks for info.

For me, the mistake was I had the configuration set at ~/.vim/.vimrc. After reading some documentation, I found that right path is ~/.vim/vimrc.

Changing the file did the trick.

TL;DR check that you don't have any inline comments in your .vimrc

After all of the helpful answers under this question I was still stuck. My ~/vimrc

set mouse-=a
set tabstop=4     " Indents will have a width of 4
set shiftwidth=4
set softtabstop=4 " Sets the number of columns for a TAB
set expandtab     " Expand TABs to spaces
syntax on
set paste
" set compatible
set t_ti= t_te= "stop ^z clearing the screen
" remember line
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" unless gitcommit
autocmd FileType gitcommit call setpos('.', [0, 1, 1, 0])

was located by vim and strace showed that it was read. Turns out that vim.basic on my system seems to ignore the entire line if it contains a comment. (So inline comments disable settings on the same line.)

I moved the "Expand TABs to spaces" comment to the previous line and instantly expandtab showed up the next time I ran vim -c :set

Related