NinjaCat
NinjaCat

Reputation: 10194

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

Upvotes: 80

Views: 93081

Answers (18)

Tomz Re
Tomz Re

Reputation: 35

For me using macOS and nvim 0.9.5 I simply ran nvim --version and it showed me the location of system vimrc:

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/Cellar/neovim/0.9.5/share/nvim"

sysinit.vim didn't exist, so I created it and added

:source ~/.vimrc

Upvotes: 0

John3136
John3136

Reputation: 29266

Stumbled on this post and none 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"

Upvotes: 6

WackGet
WackGet

Reputation: 2916

There could be errors in the .vimrc file or commands which aren't compatible with the current version of vim.

This happened to me after I copied settings from a CentOS box to Ubuntu.

To debug, run vim -S ~/.vimrc and see if it complains about any lines.

Upvotes: 0

Rojan
Rojan

Reputation: 255

Just to add on hellvinz's instruction.

After you have made vim_strace file.

cat vim_strace | grep .vimrc

makes life bit easy :)

Upvotes: 5

user821816
user821816

Reputation: 27

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.

Upvotes: 3

Thuba
Thuba

Reputation: 1

I had the same issue when I was using Vim on Parrot. I realised that I was using the regular MATE terminal when I used sudo vi ~/.vimrc. I would suggest for this edit, use Root Terminal and run the command again. This will work for all distros.

Upvotes: 0

mortenlund
mortenlund

Reputation: 47

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.

Upvotes: 1

Alexx Roche
Alexx Roche

Reputation: 3249

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

Upvotes: 0

Pranav Joglekar
Pranav Joglekar

Reputation: 747

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.

Upvotes: 1

Doru Georgescu
Doru Georgescu

Reputation: 309

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

Upvotes: 1

msb
msb

Reputation: 4398

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.

Upvotes: 3

GWu
GWu

Reputation: 2787

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.

Upvotes: 3

E. Sundin
E. Sundin

Reputation: 4181

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

Upvotes: 49

GuestUser123456789
GuestUser123456789

Reputation: 251

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

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

Upvotes: 25

Xolani
Xolani

Reputation: 1487

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

Upvotes: 3

Ben Davis
Ben Davis

Reputation: 13780

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.

Upvotes: 11

James Polley
James Polley

Reputation: 8181

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.

Upvotes: 150

hellvinz
hellvinz

Reputation: 3500

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.

Upvotes: 79

Related Questions