I would like to open NERDTree at vim startup with a specific directory root depending on an environment variable.
Set environment variables will correctly be expanded, like $HOME
. The documentation states undefined variables will expand to an empty string.
So this one works correctly with NERD_TREE_ROOT
set to an existing directory. But will not if it is undefined. Instead $NERD_TREE_ROOT
will be used like a string.
autocmd VimEnter * NERDTree $HOME/$NERD_TREE_ROOT
How can I use undefined environment variables correctly as empty string?
EDIT: To clarify a bit. This is what I wanted to avoid:
if empty($NERD_TREE_ROOT)
autocmd VimEnter * NERDTree $HOME
else
autocmd VimEnter * NERDTree $HOME/$NERD_TREE_ROOT
endif
If that is not possible it will do though.
Test whether it is empty before autocmd
:
if !empty($NERD_TREE_ROOT)
autocmd VimEnter * NERDTree $HOME/$NERD_TREE_ROOT
endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With