Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: [VIM] How to obtain Command Line Options in VIM?

21 views
Skip to first unread message

Lewis

unread,
Jun 12, 2021, 5:35:09 PM6/12/21
to
In message <ebffbd26-cf3d-4804...@post.publicly> Andreas Mattheiss <pleas...@publicly.invalid> wrote:
> I could disable that by issuing

> vim +20 -c "au\! VimEnter" myfile

> but this is terrible and not practical for everyday use.

Can't you make a macro?

--
Forgive your enemies, but remember their names.

Kenny McCormack

unread,
Jun 13, 2021, 9:04:11 AM6/13/21
to
In article <slrnscbqo7.31...@publicly.invalid>,
Andreas Mattheiss <lvzwlcykh5ucts...@antichef.net> wrote:
...
>options for vim, or, even cooler, one could query /proc/self/cmdline by
>readfile('/proc/self/cmdline').

Actually, I had been about to suggest using /proc to get the cmd line args,
when I first saw your post, but decided against it because:
1) It is a little "hacky" and people in these newsgroups often sneer at
this sort of thing.
2) It is Linux-specific, and you did not specify your OS.

But I do think it is the best overall solution, as long as you don't mind
being Linux-specific.

>Alas, both only work from version 8.2
>on, and I can't be bothered at this point to upgrade. Poor risk/reward
>prospect.

Where did you get the idea that readfile() requires 8.2 or later?

I've been using readfile() in my scripts since forever (and I am running
pretty old versions of VIM on most of my systems).

I totally agree that "upgrading" is usually not worth the risk.

--

First of all, I do not appreciate your playing stupid here at all.

- Thomas 'PointedEars' Lahn -

Kenny McCormack

unread,
Jun 13, 2021, 9:52:54 AM6/13/21
to
In article <slrnscc2gn.27...@publicly.invalid>,
Andreas Mattheiss <lvzwlcykh5ucts...@antichef.net> wrote:
>Hello,
>
>Am Sun, 13 Jun 2021 13:04:09 -0000 (UTC) schrieb Kenny McCormack
><gaz...@shell.xmission.com>:
>>
>> Where did you get the idea that readfile() requires 8.2 or later?
>>
>readfile() as such does work with earlier versions, but
>readfile('/proc/self/cmdline') will only give me the expected result
>on 8.2.

It works fine for me on all versions.

What do you think was changed in 8.2?

--
"Everything Roy (aka, AU8YOG) touches turns to crap."
--citizens of alt.obituaries--

Kenny McCormack

unread,
Jun 13, 2021, 10:46:09 AM6/13/21
to
In article <slrnscc4qc.27...@publicly.invalid>,
Andreas Mattheiss <lvzwlcykh5ucts...@antichef.net> wrote:
>Hello,
>
>Am Sun, 13 Jun 2021 13:52:51 -0000 (UTC) schrieb Kenny McCormack
><gaz...@shell.xmission.com>:
>>>readfile() as such does work with earlier versions, but
>>>readfile('/proc/self/cmdline') will only give me the expected result
>>>on 8.2.
>>
>> It works fine for me on all versions.
>>
>> What do you think was changed in 8.2?
>>
>
>hmmm, I am on version 7.2, and :echo readfile('/proc/self/cmdline') only
>comes back with "[]" when I issue gvim -R +20 myfile. Doing the same for
>an ordinary textfile with a few lines in it will work as expected. Odd.

I suppose the issue is that the cmdline file is delimited by null
characters rather than by newlines. Anyway, I was testing with 7.4 and 8.0
and could not get it to fail. It seems to just do the right thing for me.

readfile() seems to do the translation transparently.

Like you, I was testing via: :echo readfile('/proc/self/cmdline')

BTW, I assume you did have access to a system running 8.2 at some point to
test with, right?

>LISTER: Let's flag down a black cab and head for Real Street here. This
>Johnny won't come with us. He'd never fit in. Can you see him joining in
>on our late-night sessions of "pin the pointy stick on the weather girl"?

You have kewl sigs. Where do they come from?

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Voltaire

Eric Pozharski

unread,
Jun 13, 2021, 1:33:11 PM6/13/21
to
with <ebffbd26-cf3d-4804...@post.publicly> Andreas
Mattheiss wrote:

*SKIP*
> Does such a function exist, or is there a better way to bypass the
> autocommand?

:help v:argv

Hopefully, your vim is recent enough.

*CUT*

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Kenny McCormack

unread,
Jun 13, 2021, 3:46:16 PM6/13/21
to
In article <slrnscc3q3...@orphan.zombinet>,
Eric Pozharski <why...@pozharski.name> wrote:
>with <ebffbd26-cf3d-4804...@post.publicly> Andreas
>Mattheiss wrote:
>
>*SKIP*
>> Does such a function exist, or is there a better way to bypass the
>> autocommand?
>
> :help v:argv
>
>Hopefully, your vim is recent enough.

Let me guess: You were on the football team in high school, right?

OP has already explained that he knows all about v:argv and that it works
in later versions of VIM. The problem is that he wants something that will
work in his current version, which is 7.2.

Comments:
1) I just checked in 8.0 and that "help" command doesn't work. So, it
must have come in after 8.0 (8.0 is the latest version I have handy
to test ATM)

2) We were trying to get readfile() to work, but there seems to be a
disconnect between the results I was getting with readfile and what
he was getting. This disconnect remains unresolved.

--
So to cure the problem of arrogant incompetent rich people we should turn
the government over to an arrogant incompetent trust fund billionaire
who knows nothing about government and who has never held a job in his
entire spoiled life?

Lewis

unread,
Jun 13, 2021, 4:44:19 PM6/13/21
to
In message <sa5na6$25fob$1...@news.xmission.com> Kenny McCormack <gaz...@shell.xmission.com> wrote:
> In article <slrnscc3q3...@orphan.zombinet>,
> Eric Pozharski <why...@pozharski.name> wrote:
>>with <ebffbd26-cf3d-4804...@post.publicly> Andreas
>>Mattheiss wrote:
>>
>>*SKIP*
>>> Does such a function exist, or is there a better way to bypass the
>>> autocommand?
>>
>> :help v:argv
>>
>>Hopefully, your vim is recent enough.

> Let me guess: You were on the football team in high school, right?

> OP has already explained that he knows all about v:argv and that it works
> in later versions of VIM. The problem is that he wants something that will
> work in his current version, which is 7.2.

Which is how old? 15 years?

> 2) We were trying to get readfile() to work, but there seems to be a
> disconnect between the results I was getting with readfile and what
> he was getting. This disconnect remains unresolved.

And that is probably the source of the issue, whatever that difference
between your setup and his is, since even on the ancient 7.2 you got it
working.

--
"Love is like war: easy to begin but very hard to stop." - H. L.
Mencken

Eric Pozharski

unread,
Jun 15, 2021, 1:33:36 PM6/15/21
to
with <sa5na6$25fob$1...@news.xmission.com> Kenny McCormack wrote:
> In article <slrnscc3q3...@orphan.zombinet>, Eric Pozharski
> <why...@pozharski.name> wrote:
>>with <ebffbd26-cf3d-4804...@post.publicly> Andreas
>>Mattheiss wrote:

*SKIP*
> Let me guess: You were on the football team in high school, right?

At time/place I've done whatever school there were no concept of 'team'.
However, I have sense of hostility. Is it supposed to be ad hominem?

> OP has already explained that he knows all about v:argv and that it
> works in later versions of VIM. The problem is that he wants
> something that will work in his current version, which is 7.2.

At time of posting it wasn't obvious. Foreseeing further mislead
insults: are you aware of that thing called 'leafnode'?

> Comments:
> 1) I just checked in 8.0 and that "help" command doesn't work.
> So, it must have come in after 8.0 (8.0 is the latest version I
> have handy to test ATM)

It doesn't work like 'E149' or somewhat else? Anyway, vim is so great
that it doesn't bother to have changelog. That's closest I've found:
<https://github.com/vim/vim/pull/1322/commits/e17b21757e488c03ae4f07d9ca150b13>
dated 12dec2016, shitty github doesn't let my shitty elinks go any
further though.

> 2) We were trying to get readfile() to work, but there seems to be
> a disconnect between the results I was getting with readfile and
> what he was getting. This disconnect remains unresolved.

I've just found out it has been resolved. Good to know.

Spiros Bousbouras

unread,
Nov 9, 2021, 1:42:31 PM11/9/21
to
On Sun, 13 Jun 2021 14:16:44 +0000 (UTC)
Andreas Mattheiss <pleas...@publicly.invalid> wrote:
> hmmm, I am on version 7.2, and :echo readfile('/proc/self/cmdline') only
> comes back with "[]" when I issue gvim -R +20 myfile. Doing the same for
> an ordinary textfile with a few lines in it will work as expected. Odd.

For future reference (of anyone who may be interested)
:echo readfile("/proc/self/cmdline" , "b")

may work.

--
vlaho.ninja/prog
0 new messages