Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate environmental variables in a vimrc file

Tags:

vim

I am trying to do something pretty simple in my vimrc style. As you can see below I am trying to concat two environmental variables into a local variable and then use that variable.

  let cs=$menv_dotfiles_dir."/vimrc_style/".${CODING_STYLE}.".vim"                
  if filereadable(cs)                                                             
    source cs                                                                     
  endif 

Of course the above doesn't work but I think it expresses what I need to do. What is the correct way to do this?

Similar to this: Vim: sourcing based on a string But I need to do it only if the file exists.

like image 210
David Mokon Bond Avatar asked Nov 11 '13 03:11

David Mokon Bond


1 Answers

You were very close the {} brackets do not work like they do in bash. You have to use exec if you want source from a string variable.

This works:

let cs=$menv_dotfiles_dir."/vimrc_style/".$CODING_STYLE.".vim"                
if filereadable(cs)                                                             
    exec 'source ' . cs                                                                     
endif 
like image 162
cforbish Avatar answered Nov 15 '22 08:11

cforbish