1

How to invoke Linux shell env variable into vimrc ?

I split vimrc configurations into multiple files and included these files in vimrc via :runtime [file]. This works well.

:runtime vimrc.d/vimrc.pathogen           " pick one and comment others
":runtime vimrc.d/vimrc.vim-plug
":runtime vimrc.d/vimrc.vundle

After that, I want to define a variable in vimrc to specify which vimrc.x can be used.

A single or double quotation needed here for a vimrc variable

let vimrc_plugin_manager=pathogen      " It shows Undefined variable: aaa
let vimrc_plugin_manager="pathogen"    " both '' and "" here works find

The following doesn't work.

let vimrc_plugin_manager='pathogen'
:runtime vimrc.d/vimrc.&{vimrc_plugin_manager}    " This doesn't work

And finally, I want to move the variable from vimrc to shell ENV, and want it to be invoked in vimrc.

Shell

export VIMRC_PLUGIN_MANAGER=pathogen

vimrc

let vimrc_plugin_manager=&VIMRC_PLUGIN_MANAGER   " invoke shell env var to vimrc; seems not work
:runtime vimrc.d/vimrc.&{vimrc_plugin_manager}   " This doesn't work

How can it work? I have searched a lot and havent' find solution yet.

1

1 Answer 1

1

If you wrap your :runtime in an :exec you should be able to use your Vim variable.

let vimrc_customization='aaa'

:exec 'runtime vimrc.d/vimrc.' . vimrc_customization
3
  • Sorry I edit the question again and use my own case here. I tried let vimrc_plugin_manager='pathogen' and ` :exec 'runtime vimrc.d/vimrc.'.vimrc_plugin_manager ` , the two blankspace removed , seems didn't work.
    – Robert Hu
    Sep 29, 2020 at 4:22
  • wrap :runtime in an :exec , YES, it can work. :exec 'runtime vimrc.d/vimrc.pathogen'
    – Robert Hu
    Sep 29, 2020 at 4:25
  • Yes, It woks now. Have to remove : before runtime and concatenate string variables with .
    – Robert Hu
    Sep 29, 2020 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.