Skip to content

Implement :source ex command #9983

@digitalby

Description

@digitalby

Running :source {file} currently errors with Command :so[urce] is not yet implemented (PRs are welcome!) because the entry at src/vimscript/exCommandParser.ts uses the undefined stub that falls through to UnimplementedCommand.

Proposal

Implement :source by reading the file and, for each non-blank / non-comment line:

  1. Try the three vimrcKeyRemappingBuilder paths (remap, unmap, mapclear) and apply to configuration via the existing public VimrcImpl.{add,remove,clear}RemapFromConfig helpers. This mirrors what src/configuration/vimrc.ts already does at startup so :nnoremap / :unmap / :mapclear work as users expect.
  2. Otherwise feed the line through ExCommandLine.parser.tryParse(...) and execute the resulting command. This is the same pattern :foldclose / :folddoopen already use to re-enter the ex-command parser. It naturally supports :set, :edit, :nohl, nested :source, and anything else already implemented.

Path resolution: expand ~ / $HOME, then resolve relatives against the first workspace folder (or the active document's directory when there is no workspace). Cycle detection via a static Set<string> of currently-being-sourced absolute paths, rejecting re-entry with E1092. Missing files report E484.

I have this implemented locally with tests covering basic mapping load, comments/blanks, nested source, cycle detection, missing file, and regular ex-command execution. Full test suite stays green. Will open a PR referencing this issue shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions