Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim use a variable interpolated within a String?

Tags:

vim

zshrc

I have a .zshrc and .vimrc file

In my .zshrc file I have syncfolder="$HOME/Google Drive/Dropbox"

I now want to reference syncfolder within my .vimrc file, is this possible (if so, how)?

Also, within my .vimrc file I'm sourcing lots of other files and I want to make that more efficient.

The following doesn't work:

let vimfolder="~/Google Drive/Dropbox/Fresh Install/Shell/vim"

source "$vimfolder/settings.vim"
source $vimfolder/vundle.vim
source $vimfolder/mapping.vim
source $vimfolder/filetypes.vim
source $vimfolder/commands.vim

...I've tried multiple variants where vimfolder included $HOME and in another I've tried exporting a variable from my .zshrc file, like so...

export SYNCFOLDER=$syncfolder

...in the hope that I could access it from within my .vimrc but it didn't work.

Any ideas?

like image 418
Integralist Avatar asked Nov 13 '13 10:11

Integralist


1 Answers

You need to use :execute to evaluate a variable in most Ex commands. Vim variables do not have a $ prefix, those are environment variables (which you can reference from Vimscript, too):

execute 'source' vimfolder . '/settings.vim'

However, in this particular case, I'd rather add the location to 'runtimepath' and then use :runtime:

set runtimepath+=~/Google\ Drive/Dropbox/Fresh\ Install/Shell/vim
runtime settings.vim

Another alternative is symbolic links, so you don't have change anything in your Vim setup.

like image 183
Ingo Karkat Avatar answered Sep 18 '22 17:09

Ingo Karkat