vim cannot open file when run from .vimrc, but can open fine when run from terminal

Viewed 5162

Whenever I try to open any file with Vim I get this error message:

Error detected while processing /home/emma/.vimrc:
line  138:
E484: Can't open file '/home/emma/.opam/system/share/ocp-indent/vim/indent/ocaml.vim'
Press ENTER or type command to continue

But the strange thing is that when I do this, the file actually opens:

vim ~/.opam/system/share/ocp-indent/vim/indent/ocaml.vim

So I've verified that the file does exist and that Vim is capable of displaying the code.

Here are lines 120 to the end of my .vimrc: enter image description here

And here is the entirety of ~/.opam/system/share/ocp-indent/vim/indent/ocaml.vim: enter image description here

1 Answers

When vim says

E484: Can't open file '/home/emma/.opam/system/share/ocp-indent/vim/indent/ocaml.vim'

it literally means a file called,

'/home/emma/.opam/system/share/ocp-indent/vim/indent/ocaml.vim'

not

/home/emma/.opam/system/share/ocp-indent/vim/indent/ocaml.vim

In other words, the problem is the quotes you added around the filename.

Fix:

  source /home/emma/.opam/system/share/ocp-indent/vim/indent/ocaml.vim

Also, you could use ~ there:

  source ~/.opam/system/share/ocp-indent/vim/indent/ocaml.vim
Related