This is a interesting question and I'm not sure I fully understand what is
going on. So here are my findings based on my Vim setup.
My setup contains some plugins (mainly self written) installed in
~/.vim/pack/.../start. These plugins all require Vim to run in
nocompatible mode (see
I looked at two different scenarios:
vim -E testfile and enter the commands manually
vim -E testfile <<-EOS... with a here document as in your question
In the first case Vim exists with 0 in the second with 1.
By running scenario 2 with
-V9 I found that one of my plugins has an autocmd
for the BufWritePre event and that the code of the called function is not parsed
correctly. This error happens, as Vim is running in
From the verbose output of Vim I can see, that my
~/.vim/vimrc is not
loaded, but all my plugins are loaded. This explains why vim is in
Investigating scenario 1 shows, that my
~/.vim/vimrc is loaded and hence
Vim runs in
nocompatible mode. In that case everything works fine.
Why is my
vimrc only loaded in scenario 1?
My interpretation is, that Vim detects that input is from a terminal. In that
case I could enter
visual at the ex-prompt to switch to "normal" Vim. So Vim
is preparing for that.
In scenario 2 Vim detects, that input is not a terminal (it's the here-document)
and it is not possible to switch to visual. Even if you add
visual to your
here-document, Vim will not switch to visual (it can't as it has no access to terminal input).
Why are all the plugins loaded?
To be honest: I don't know. I think that it is fair to assume, that most
plugins need Vim to run in
nocompatible mode. So it doesn't make sense to
In my case everything works smooth if I force Vim to run in
mode by adding the option
$ vim -N -E testfile <<-EOS