Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent mode ex (-s) has different exit code than non-silent based on presence of line continuation in vimscript plugin #5628

Closed
lucianposton opened this issue Feb 12, 2020 · 5 comments

Comments

@lucianposton
Copy link

Describe the bug
ex -s exits with failure code (1) while ex exits success code (0) when a plugin's vimscript contains a line continuation with backslash.

Examples of vimscript causing this issue:

command! -bang -nargs=+ -range=0 -complete=file AsyncRun 
	\ call asyncrun#run('<bang>', '', <q-args>, <count>, <line1>, <line2>)
echo "a
            \ b"

Example of vimscript not causing this issue:

echo "a b"

To Reproduce
Step 1:
Empty ~/.vimrc and ~/.vim.
Step 2:

echo "foo" > /tmp/test.file

Step 3:

ex -sc '%s/foo/bar/|x' /tmp/test.file

Step 4:

$ echo $?
0

Step 5:

echo "foo" > /tmp/test.file

Step 6:

ex -c '%s/foo/bar/|x' /tmp/test.file

Step 7:

$ echo $?
0

Step 8:

mkdir -p ~/.vim/plugin && echo "echo \"a\n            \\\\ b\"" > ~/.vim/plugin/bug.vim

Step 9:

echo "foo" > /tmp/test.file

Step 10:

ex -sc '%s/foo/bar/|x' /tmp/test.file

Step 11:

$ echo $?
1

Step 12:

echo "foo" > /tmp/test.file

Step 13:

ex -c '%s/foo/bar/|x' /tmp/test.file

Step 14:

$ echo $?
0

Step 15:

echo "echo \"a b\"" > ~/.vim/plugin/bug.vim

Step 16:

echo "foo" > /tmp/test.file

Step 17:

ex -sc '%s/foo/bar/|x' /tmp/test.file

Step 18:

$ echo $?
0

Step 19:

echo "foo" > /tmp/test.file

Step 20:

ex -c '%s/foo/bar/|x' /tmp/test.file

Step 21:

$ echo $?
0

Expected behavior
Expected behavior is that step 11 has the same exit code as steps 4, 7, 14, 18, and 21.

Environment (please complete the following information):

  • Vim version: 8.2.0055, also tested with 8.2.0246 compiled from source
  • OS: gentoo linux
  • Terminal: rxvt-unicode

Additional context

@tonymec
Copy link

tonymec commented Feb 12, 2020

What is 'compatible' set to? :verbose set cp? (as a line in your script in your -s runs, or typed from the keyboard otherwise) will tell you. Since this is a Boolean option, the question mark at the end is important.

compatible needs to be off for continuation lines (lines starting with a backslash in sourced scripts) to be recognised as such.

  • If Vim finds a vimrc (even an empty one), that wil set 'nocompatible'
  • If a recent version of Vim finds neither a vimrc nor an exrc, it will source $VIMRUNTIME/defaults.vim, which will set 'nocompatible'
  • if the command-line includes -u DEFAULTS recent versions of Vim will skip any vimrc but will load the defaults.vim (which sets 'nocompatible')
  • In recent versions of Vim, --clean on the command-line is equivalent to -u DEFAULTS -U NONE -i NONE
  • If the command-line includes -u NONE (with a lowercase u) Vim will look for neither a vimrc nor a defaults.vim; it will also not load global pugins. 'compatible' is then on by default (in the absence of a -N switch, see below)
  • If the command-line includes -N Vim will start in 'nocompatible' mode even if no startup scripts are read
  • If the command-line includes -C Vim will start in 'compatible' mode even if a vimrc is found (but a set nocompatible statement in a vimrc and/or a defaults.vim may change that).
  • I'm not sure which of the above apply when starting Vim as ex, and what changes depending on the -s switch to ex (or to vim -e)

@lucianposton
Copy link
Author

In my original repro steps, 'compatible' is set to on for ex -s according to :verbose set cp?.

With either echo "set nocompatible" > ~/.vimrc or with no ~/.vimrc, 'compatible' is set to on for ex -s, while it is set to off for ex (no -s). With echo "set compatible" > ~/.vimrc, 'compatible' is set to on for both ex and ex -s.

Both -N and -u DEFAULTS caused ex -s to turn off 'compatible', resulting in a success exit code as expected in the repro steps from my initial report.

It would appear that the underlying issue is ex -s ignores set nocompatible in .vimrc. Or is there a good reason for that behavior? Thoughts?

@tonymec
Copy link

tonymec commented Feb 12, 2020

Looks like ex -s does an accelerated startup, ignoring vimrc and defaults.vim unless explicitly told otherwise on the command-line.

I think this is intentional, to make batch-mode behaviour more reproducible (by implying -u NONE unless told otherwise). But it might be an oversight. @brammool : what do you think?

@lucianposton : if your batch script contains continuation lines, or if it otherwise relies on nocompatible being set, it's a good idea to start that script with a line saying set nocompatible.

@lucianposton
Copy link
Author

Looks like ex -s does an accelerated startup, ignoring vimrc and defaults.vim unless explicitly told otherwise on the command-line.

I think this is intentional, to make batch-mode behaviour more reproducible (by implying -u NONE unless told otherwise). But it might be an oversight.

If indeed ex -s should ignore ~/.vimrc and defaults.vim, it seems odd to me that plugins would be loaded from .vim/plugin.

@brammool
Copy link
Contributor

See :help -s-ex
This mode is mostly for backwards compatibility, using ex to execute a script.
Changing behavior would break those scripts.
It is indeed an odd mode. So don't use it :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants