开发者

Not reading ~/.vimrc

I have a ~/.vimrc file that vim doesn't seem to be reading. There is a file at /etc/vimrc, an开发者_如何学Cd 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.


Just to add on hellvinz's instruction.

After you have made vim_strace file.

cat vim_strace | grep .vimrc

makes life bit easy :)


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"


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


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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜