testfile $ cat testfile foo bar $ vim -E testfile <<-EOS > 1 > s/foo/baz/ > x > EOS $ echo " /> testfile $ cat testfile foo bar $ vim -E testfile <<-EOS > 1 > s/foo/baz/ > x > EOS $ echo " /> testfile $ cat testfile foo bar $ vim -E testfile <<-EOS > 1 > s/foo/baz/ > x > EOS $ echo "/>

Why is `vim -E` always exiting with non-zero exit code when using here-doc?

108 views Asked by At

see the following session in dash:

$ printf "foo\nbar\n" > testfile
$ cat testfile
foo
bar
$ vim -E testfile <<-EOS
> 1
> s/foo/baz/
> x
> EOS
$ echo $?
1
$ cat testfile
baz
bar
$ vim -E testfile +'1' +'s/baz/foo/' +'x'
$ echo $?
0
$

I use ex-mode of vi for exchaning the string foo with the string baz by using a here-document. Apparently that works. But nevertheless vim is still existing with an exit code of 1.

I then exchange the baz with foo again by giving the commands directly on the commandline to vim. That works too and returns with exit code of 0 (as expected).

What is the reason the here-document is always returning with an exit code of 1?

That even happens if I do not edit the file:

$ vim -E testfile <<-EOS
> 1
> p
> q
> EOS
foo
$ echo $?
1
$ 

What's going on there?

1

There are 1 answers

0
radlan On

I asked the same question on vi.stackexchange.com now (which seems a bit more appropriate) and got a really useful answer there: https://vi.stackexchange.com/a/19241/21417