1

Im experiencing some problems running a command that reports paths based on the $PWD.

To correctly parse its output I need it to run from a different directory, however, I would rather not have to cd into that path in the current vim instance.

Is this possible?

Or is there a way to do this which doesn't manipulate the working directory history?

3

Yes, it's possible. You can run the command in a sub-shell (assuming that you're running in Unix and not Windows) and include a cd command at the start of the sub-shell. For example,

:!(cd /usr/local; ls)

Or even simpler,

:!cd /usr/local; ls
  • 4
    I've come to prefer :!cd path && command (or system('cd path &&..., or job_start). This way if the path isn't accessible (whatever the reason), I got rejected. – Luc Hermitte Sep 7 '16 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.