Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:08:59+00:00 2026-05-31T05:08:59+00:00

I would like to open NERDTree at vim startup with a specific directory root

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:09:00+00:00Added an answer on May 31, 2026 at 5:09 am

    What you observe has nothing to do with eval or expressions: echo eval('$HOME/$NERD_TREE_ROOT') results in -2147483648 just like echo 0/0 because both variables when performing a numeric operation turn out to be zeros. The expansion of $HOME is performed by vim due to presence of -complete=dir in :NERDTree command definition. This is rather unexpected and, by the way, is the third type of expansion: :echo expand('$HOME/$NERD_TREE_ROOT') results in $HOME/$NERD_TREE_ROOT while :echo expand('$HOME/$HOME') results in /home/zyx//home/zyx. I do not see any way to fix this, but you can always do

    execute 'autocmd VimEnter * NERDTree '.fnameescape($HOME.'/'.$NERD_TREE_ROOT)
    

    . It is the only case when expansion works as described in the doc because it is the only way when there are any expressions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to open a new tab (or window, depending on the user's
I would like to open an Ext.Window in ExtJS , that will open an
I have multiple hidden files in a directory and would like to open and/or
I recently started using NERDTree with vim, and have set it to automatically open
i have a code generator project i would like to offer like open source,
I would like to open a small video file and map every frames in
I would like to open an OleDbConnection to an Excel file that's in memory
I would like to open a document after my ASP.NET page loads in a
I would like to open up the compose page for gmail in an iframe
I would like to open a popup window using javascript in my c#.net app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.