0

I have configured my .vimrc to make my vim work, and then I renamed my .vimrc to be .vimrc2. After that my vim can run as clean mode, but when I run my vim with vim -u .vimrc2, there are errors like this:

E10: \ should be followed by /, ? or &
line   59:
E10: \ should be followed by /, ? or &
line   60:
E10: \ should be followed by /, ? or &
line   61:
E10: \ should be followed by /, ? or &
line   73:
E117: Unknown function: pathogen#infect
E15: Invalid expression: pathogen#infect()

How could I make it work? My .vimrc2 works well if it is renamed to be .vimrc and no -u options are used.

Edit:

my vimrc is here: https://github.com/CoinCheung/learn-coding-notes/blob/master/vim/00-vimrc

3
  • Can you post the contents of this vimrc? See also help -u: some initializations are skipped and compatible will be set (which you should disable in your vimrc)
    – D. Ben Knoble
    Dec 28, 2018 at 4:14
  • @D.BenKnoble Thanks, see my updates for vimrc please. Dec 28, 2018 at 11:33
  • 1
    If the file $HOME/.vimrc exists, Vim switches to nocompatible and then sources the file. By giving the file with -u .vimrc2 the file is sourced in compatible mode. So you should add set nocompatible at the beginning of that file.See :help .vimrc.
    – Ralf
    Dec 28, 2018 at 12:01

1 Answer 1

5

Vim will automatically set nocompatible when loading ~/.vimrc or ~/.vim/vimrc. But it's not set automatically when loading a file with the -u option, or using :source.

The solution is to add set nocompatible to the .vimrc2 file, or use the -N flag to set it (vim -N -u .vimrc2).

Personally I think it's always a good idea to add set nocompatible to vimrc files exactly to avoid this confusion, even if it's not strictly needed when loading from the default locations. But some people are dead-set against it 🤷‍

2
  • Another option is an if &compatible guard
    – D. Ben Knoble
    Dec 28, 2018 at 13:49
  • set nocompatible also worked for me but I don't understand why? I installed a new vundle package hashi-vim/vim-terraform for Terraform syntax highlighting so it must be something to do with this. Anyway, I don't seem to be loosing anything by being in nocompatible mode for now but if anyone has any insights, that would be great! Apr 13, 2022 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.