Skip to content

Conversation

SanzharKuandyk
Copy link

@SanzharKuandyk SanzharKuandyk commented Sep 23, 2025

Note: descriptions are AI-generated

Add v:argf to track original startup file arguments #35847

Problem

  • :args and argv() can change after startup.
  • v:arg includes options/commands, not just files.
  • Plugins (e.g. Oil) may rewrite directory args.

Solution

  • New read-only var v:argf: snapshot of file/dir args at startup.
  • Unaffected by :args or plugins.
  • Unlike v:argv, excludes options/commands.

Example

nvim file1.txt dir1 file2.txt
echo v:argf
" ['file1.txt', 'dir1', 'file2.txt']

fix #35847

@justinmk
Copy link
Member

justinmk commented Sep 23, 2025

Looks ok to me, but the verbosity indicates that this was AI generated. Always mention that, and also please prune the irrelevant details where possible. The PR, and its description, should be complete yet concise.

And as the issue label indicates, I would prefer if I heard whether people actually want this feature, or if I missed some other possible way to achieve it already.

@SanzharKuandyk
Copy link
Author

Thank u for the feedback!

And as the issue label indicates, I would prefer if I heard whether people actually want this feature, or if I missed some other possible way to achieve it already.

Yeah, keeping this as a draft

Introduce the read-only Vim variable v:argf that stores the original
file arguments passed at startup. Unlike v:argv, v:argf contains only
raw file arguments and remains unchanged by :args commands or plugins.

This is implemented via set_argf_var() called at startup, and documented
in runtime/doc/vvars.txt. VV_ARGF is registered as a VAR_LIST and VAR_RO.
See |v:progpath| for the command with full path.

*v:argf* *argf-variable*
v:argf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphanumeric order. this should go before v:argv

VV(VV_VERSIONLONG, "versionlong", VAR_NUMBER, VV_RO),
VV(VV_ECHOSPACE, "echospace", VAR_NUMBER, VV_RO),
VV(VV_ARGV, "argv", VAR_LIST, VV_RO),
VV(VV_ARGF, "argf", VAR_LIST, VV_RO),
Copy link
Member

@justinmk justinmk Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should go before ARGV

VV_VERSIONLONG,
VV_ECHOSPACE,
VV_ARGV,
VV_ARGF,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should go before ARGV

See |v:progpath| for the command with full path.
]=],
},
argf = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before argv

list_T *list = tv_list_alloc(kListLenMayKnow);

for (int i = 0; i < GARGCOUNT; i++) {
char *fname = alist_name(&GARGLIST[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should expand the filename to an absolute path, since CWD can change after startup, which would make v:argf not very useful thereafter.

And need a test for that scenario.

Also need tests for the -- case:

nvim ... -- file1 file2

And need tests that check what happens if the user calls :argadd in a -c or --cmd option:

nvim --cmd "argadd file1.txt" -c "argadd file2.txt"

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

Successfully merging this pull request may close these issues.

v:argf gets file/directory args passed at startup
2 participants