Not reading ~/.vimrc
Asked Answered
H

18

79

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
Hangbird answered 16/8, 2010 at 16:21 Comment(7)
They're both run. /etc/vimrc should be loaded first, then ~/.vimrc should be loaded. There are a few other things loaded, most of which are contained in your ~/.vim/ directory. Don't know why yours isn't loading.Subclavius
I modified the question to include the strace output... Does the root folder vimrc override the settings in /etc/vimrc?Hangbird
Do you mean to use /root/.vimrc or do you want to use /home/ninjacat/.vimrc (or similar)?Hubbs
Well, for this user, /root/.vimrc is fine. I haven't played with the other user yet.Hangbird
/root/.vimrc is what ~/.vimrc means in your situation (which you haven't described in the question), check the HOME environment variable (printenv HOME or echo $HOME). If you want ~/.vimrc to mean something else (i.e. /home/.../.vimrc), then you need to change something outside of vim.Hubbs
In other words, vim is reading ~/.vimrc, but ~ means /root and it seems you didn't expect that.Hubbs
apparently, my vim version 8.x on cygwin is looking in ~/.vim/vimrcDiallage
R
79

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.

Rowdyism answered 16/8, 2010 at 16:46 Comment(3)
This is a slick way of figuring this out.Ohmmeter
Note that some virmrc files are not in your home directory. I'm running Raspbian, and mine was in /usr/share/vim/vimrc.Feriga
I wish I new about the strace command years ago. This is extremely useful; thank you.Okajima
U
148

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.

Ultun answered 14/3, 2012 at 11:7 Comment(4)
This was useful +1. Unfortunately, for some reason, although syntax.vim shows up on my scriptnames it's still the only command in my vimrc not getting read or showing up in the :verbose set, any ideas?Forecourt
This is helpful but does not solve the problem. Now I know ~/.vimrc has not been read, but why is that happening?Win
Maybe look at :h MYVIMRC for more information how vim reads his configs.Gaona
scriptnames tells me that there are 24 files being read - mostly from my \vim82\ installation directory. Why so many? I thought it just reads one VIMRC file??Winegrower
R
79

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.

Rowdyism answered 16/8, 2010 at 16:46 Comment(3)
This is a slick way of figuring this out.Ohmmeter
Note that some virmrc files are not in your home directory. I'm running Raspbian, and mine was in /usr/share/vim/vimrc.Feriga
I wish I new about the strace command years ago. This is extremely useful; thank you.Okajima
B
47

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
Boyt answered 28/10, 2017 at 21:5 Comment(7)
Note, you can simply add source ~/.vimrc in ~/.config/nvim/init.vim to source configs without relying on symbolic links.Foggy
Thank you so much you saved me a lot of time.Viewy
Thanks for sharing. This has helped me.Hades
This help me tooPosner
Good to know this caveat for NeoVim. This helped me (accepted answer was not useful as I saw ~/.vimrc in the trace of vim, but vim was not loading it). Thanks!Kedah
you mean init.luaMord
Thanks. This was much needed. I was struggling until I found this solution.Untoward
W
25

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

alias vim="vim -S ~/.vimrc"
Willenewillet answered 10/2, 2015 at 0:22 Comment(5)
The real question is why do you have this problem (and me as well)Autotomy
This could happen if you're really using neovim but have it aliased to vimBoyt
I have neovim and have a symbolic link for vim (probably should've aliased), and had this problem. GuestUser123456789's solution fixed it.Vacuum
Since this answer is attracting NeoVIM users: Your default config is at ~/.config/nvim/init.vim Please add source ~/.vimrc to render the .vimrc settings.Foggy
I seem to have this issue with Fedora Sway Atomic (Fedora Silverblue with Sway window manager) and Vim, not Neovim. I was looking through the command line flags but could not find "config" and did not know that the -S flag does what I want. This helped me, thank you! (:scriptnames does not work in my Vim, saying "Sorry, the command is not available in this version.")Cobbs
G
11

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.

Gynaecocracy answered 7/5, 2014 at 16:19 Comment(3)
THANK YOU! sudo - E didn't work for me, but I just changed the color scheme for the root user as well:-)Vlada
This worked for me. Note that there is no space between - and E, but even if -E doesn't work, copying your own .vimrc file to /root also does the trick!Clothing
Thank you so much. Every time that bell went off it was like a little sledgehammer to my frontal cortex.Miticide
V
6

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"

Viscacha answered 8/10, 2020 at 0:42 Comment(2)
Yes, vim --version on CentOS 7 shows these locations: system vimrc file: "/etc/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc"Thymol
Same here, on Fedora Sway Atomic (Fedora Silverblue with Sway window manager) it seems to be "~/.virc".Cobbs
D
5

Just to add on hellvinz's instruction.

After you have made vim_strace file.

cat vim_strace | grep .vimrc

makes life bit easy :)

Draconian answered 16/8, 2010 at 17:6 Comment(1)
grep .vimrc vim_strace is even better.Rhetic
B
3

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.

Ballard answered 29/6, 2011 at 19:41 Comment(1)
10.8? I'm on 10.7.3 in 2012... I want to know how you got to 10.8 last year.Fahy
O
3

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

Outlier answered 14/5, 2014 at 9:26 Comment(0)
R
3

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.

Ruel answered 28/5, 2018 at 13:49 Comment(0)
D
3

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.

Daile answered 15/5, 2019 at 20:53 Comment(0)
H
1

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

Hosfmann answered 1/10, 2020 at 12:1 Comment(0)
A
1

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.

Ampulla answered 15/4, 2022 at 20:11 Comment(0)
G
0

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.

Glomerate answered 13/11, 2020 at 6:30 Comment(1)
This was it!!!!Topknot
A
0

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

Auden answered 25/12, 2021 at 17:25 Comment(0)
M
0

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.

Microgamete answered 11/9, 2023 at 8:15 Comment(0)
D
0

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.

Diaz answered 26/4 at 3:34 Comment(0)
D
0

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
Donny answered 10/5 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.