Search code examples
vimnerdtree

Using NERD tree as a Vim sidebar


I'm a new user of NERD tree in Vim and am obviously not that much familiar with its features.

When I'm using :NERDTreeToggle, the sidebar window always opens my home directory, ~. How can I change the default directory (like open a project in Sublime Text)?

Also, how can I keep this sidebar window open in all of the new tab windows (something like the Sublime Text sidebar)? Or at least, is there another alternative to this task?


Solution

  • Vim has no concept of "project".

    The closest you can get without installing clunky plugins is the "current directory": when you start Vim, the "current directory" is set to the directory where you started Vim.

    In your shell, this is easy to manage:

        $ cd /path/to/project
        $ vim
        :pwd --> /path/to/project
    

    If you use gVim or MacVim, the "current directory" is usually set automatically to $HOME if you start Vim without a file so, either you find a way to start Vim in an arbitrary directory or you use :cd /path/to/dir as soon as possible.

    Without argument, the :NERDTree* commands open the NERD tree window in the "current directory".

    You can use :NERDTreeToggle /path/to/dir to make it display the content of a specific directory.

    Or you can make sure you start Vim from your project's directory and NERD tree will do what you want it to do.