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


Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

I had this problem and just added the following to the file ~/.bash_profile:

alias vim="vim -S ~/.vimrc"

Solution 5:[5]

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.

Solution 6:[6]

Just to add on hellvinz's instruction.

After you have made vim_strace file.

cat vim_strace | grep .vimrc

makes life bit easy :)

Solution 7:[7]

On OSX 10.8.0 the location of the vimrc file is: /usr/share/vim/vimrc

I just add my changes to the bottom of the file.

Of course this has the effect of making the changes for all users. For the life of me I can't seem to figure out how to get it to read ~/.vimrc. This was never an issue for me on 10.6.x

Anyway this is a quick fix even it is a bit dirty.

Cheers

Solution 8:[8]

use file /etc/vim/vimrc.local in Ubuntu

Solution 9:[9]

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"

Solution 10:[10]

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.

Solution 11:[11]

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.

Solution 12:[12]

/etc/vim/vimrc is now overwritten by defaults.vim unless there is a ~/.vimrc, apparently. https://github.com/vim/vim/issues/2042

Solution 13:[13]

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.

Solution 14:[14]

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.

Solution 15:[15]

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