External commands do not always run in correct directory or environment
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.2k
- Forks
- 1.5k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 6
Description
Describe the bug
External commands in Windows do not run from current directory (instead running from /c/Program Files/VSCodium), and when using Remote WSL or Remote SSH do not run in correct environment (they still run in Windows CMD). Applies to both :r !cmd and :'<,'> !cmd.
To Reproduce
Steps to reproduce the behavior:
In local Windows environment:
- Open a folder in VSCodium
- Open a file in that folder
- Run
:r !dir - Output printed to file indicates " Directory of C:\Program Files\VSCodium", and so the command was run from wrong directory.
In Remote WSL or SSH:
- Open a Remote WSL session, or a Remote SSH to a Linux device.
- Run
:r !ls. Vim output in console reports error executing command and "ls is not recognized as an internal or external command", indicating command was run in Windows and not Linux.
Same behavior occurs if one highlights some text, goes into visual mode with V and then tries !dir.
Expected behavior
Commands are run in the correct environment and same directory as current file, which is the behavior in Vim.
Screenshots
If applicable, add screenshots to help explain your problem.
If remapping-related, please attach log output: https://github.com/VSCodeVim/Vim#debugging-remappings.
Output of :r dir when running in local Windows:
Error message from running in VSCode WSL:
Environment (please complete the following information):
- Extension (VsCodeVim) version: 1.30.1
- Open Remote SSH by Jeanp ver 0.049
- Open Remote WSL by Jeanp ver 0.0.5, using WSL version 2.5.10.0
- VSCode version: 1.87
- OS: Windows 11 Enterprise
Additional context
This is an extension of the long-standing issue reported here, which indicates that the read command doesn't use correct environment/directory for files either: https://github.com/VSCodeVim/Vim/issues/6678.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the :r !cmd and visual !cmd entry points, then inspect how the extension selects the working directory and execution environment for local Windows and Remote WSL or SSH sessions. Done means commands run from the current file's directory in the matching local or remote environment for both reported command forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100