feat(startup): provide v:argf for file arguments #35889

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.
- Paths are resolved to absolute paths when possible

Example:

    nvim file1.txt dir1 file2.txt
    :echo v:argf
    " ['/home/user/project/file1.txt', '/home/user/project/dir1', '/home/user/project/file2.txt']
This commit is contained in:
Sanzhar Kuandyk
2026-02-25 13:38:08 +05:00
committed by GitHub
parent 6d73bf4886
commit cf874cee33
7 changed files with 152 additions and 0 deletions

View File

@@ -6,6 +6,21 @@ error('Cannot require a meta file')
--- @class vim.v
vim.v = ...
--- The list of file arguments passed on the command line at startup.
---
--- Each filename is expanded to an absolute path, so that v:argf
--- remains valid even if the current working directory changes later.
---
--- Unlike `v:argv`, this does not include option arguments
--- such as `-u`, `--cmd`, or `+cmd`. Unlike `argv()`, it is not
--- affected by later `:args`, `:argadd`, or plugin modifications.
--- It also handles the `--` separator correctly, including only
--- files specified after it.
---
--- This is a read-only snapshot of the original startup file arguments.
--- @type string[]
vim.v.argf = ...
--- The command line arguments Vim was invoked with. This is a
--- list of strings. The first item is the Vim command.
--- See `v:progpath` for the command with full path.