0

Can you edit a vim session, so that it opens a file based on the value of an environment variable instead of an absolute path to a file?

  • With exec and edit, almost certainly. Automating it would be tough. The real question: why? – D. Ben Knoble Aug 22 at 18:10
  • If for instance you want to edit the same files on another machine mounted at a different place. – leeand00 Aug 22 at 18:11
  • OneDrive can cause this; sharing the files via SMB and then mounting them somewhere else. – leeand00 Aug 22 at 18:12
  • Why the same files on another machine mounted at another place? If replicating files across systems, perhaps puppet/ansible is the right tool. Or, could use different sessions (one for each machine). Or use rsync to move files around. Or standardize the mount points. Etc. – D. Ben Knoble Aug 22 at 18:14
  • Because I can’t. I’m using two different windows computers with two different usernames so the “home” directory where OneDrive mounts them is different. – leeand00 Aug 22 at 18:16
1

After saving a session to a file you can edit it and replace parts of the path with the environment variables:

Original:

set ...
edit C:\Users\yourname\Some\Path\file.txt
set ...

Modified:

set ...
edit $HOME\Some\Path\file.txt
set ...

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.