On 2021-03-25, Gary Johnson wrote:
> On 2021-03-25, Christian Brabandt wrote:
> > On Mi, 24 Mär 2021, Ron Aaron wrote:
> >
> > > I want to get the vim version for a bash script. The way I'm trying to use is:
> > >
> > > vim --not-a-term --cmd 'echo v:versionlong|quit'
> > >
> > > However, that spews a bunch of ANSI terminal control stuff as well, which I don't want. Is there an option to suppress that output?
> >
> > Have you tried TERM=dumb vim --cmd 'echo v:versionlong|quit'?
>
> I did. It eliminated all but t_cm and added a ^M.
I think this is partly a bug in Vim. There are a few places in the
code where Vim assumes that it is running in a terminal as it
normally does and should output terminal control sequences without
regard to the presence of --not-a-term.
I have attached a patch that seems to fix that problem. If someone
would rather I submitted a PR, I can do that, too. Since this is
just a proposal at this point, the patch was just easier for me.
Even with the patch, though, I think using :echo to send something
to stdout is incorrect. The :echo command is intended to write to
the screen and does so under the control of Vim's screen management.
I think it would be a mistake to modify that code to have :echo
write to the screen or directly to stdout. I think a better
approach is to use echoraw() when you want to write directly to
stdout.
That would change your command to this:
vim --not-a-term --cmd 'call echoraw(v:versionlong)|quit'
If you want to put a newline on the end of that, use this:
vim --not-a-term --cmd 'call echoraw(v:versionlong."\n")|quit'
Of course, neither of those will do what you want without my patch
applied. We'll have to see if Bram et al. think that's a good idea.
Regards,
Gary