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 ♦Commented Aug 22, 2019 at 18:10
-
If for instance you want to edit the same files on another machine mounted at a different place.– leeand00Commented Aug 22, 2019 at 18:11
-
OneDrive can cause this; sharing the files via SMB and then mounting them somewhere else.– leeand00Commented Aug 22, 2019 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 ♦Commented Aug 22, 2019 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.– leeand00Commented Aug 22, 2019 at 18:16
|
Show 2 more comments
1 Answer
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 ...