0

tldr: The title pretty much summarizes the entirety of the question

I am trying to make my configuration more adaptable to different machines so that I can use git to keep them in sync between my personal windows, linux, and work machines. right now my .vimrc/init.vim passes absolute literal paths to the source key word and it works fine, but say I want to do something like this...

if has('win32')
   let prefix = $HOME . '/AppData/Local/nvim'
else
   let prefix = $HOME . '/.config/nvim'
endif

source prefix . '/vim-plug/plugins.vim'

This doesn't work because the source keyword interprets everything literally. So how can I make it expand the variables?

Here are some things i've tried

source exec expand(prefix) . '/rest/of/path'

source <exec> expand(prefix) . '/rest/of/path'

source <exec> prefix . '/rest/of/path'

exec source prefix . '/rest/of/path'

and many other variations

As I have been unsuccessful in finding an answer in a search engine, I've resorted to guessing different variations of this which is tedious and unproductive. So does anyone know how to make this work?

New contributor
Riley Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
5
1

:h expand() your string with environment variable, concatenate it the rest and use :h :execute to source it:

:execute "source " . expand(prefix) . "/whatever.vim"

Your Answer

Riley Hughes is a new contributor. Be nice, and check out our Code of Conduct.

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.