How to highlight current file in NERDTree

I typically navigate in source files using Ctags information in Vim. It would be useful if I could see where in the directory hierarchy the file I jumped into is. I can see this in the NERDTree window using :NERDTreeFind.

However, it would be neat if this happened automatically when I jumped into a file. Here is code from Lambart that makes it happen. Just add it to your vimrc file to take effect:

Tried with: Vim 7.4 and Ubuntu 14.04

Advertisements

3 thoughts on “How to highlight current file in NERDTree

  1. I tried adding this to my .vimrc on OSX. I see that when I open the NERDTree manually, it opens in the main vim window.
    The solution to this was to autoopen NERDTree when vim start. This can be done using:
    au VimEnter * NERDTree

    Like

  2. It’s working but πŸ™‚
    If the file is out of the scrolling area of NERDTree the file is highlighted but the window buffer on NERDTree is not scrolled to ensure visibility of the selected element. Is there a way to fix this ?
    Anyway, thank you for this tip!

    Like

  3. With vim 7.4 in MacOS I get the following errors:

    Error detected while processing /Users/xpunk/.vimrc:
    line 75:
    E128: Function name must start with a capital or “s:”: rc:isNERDTreeOpen()
    line 76:
    E133: :return not inside a function
    line 77:
    E193: :endfunction not inside a function
    line 81:
    E128: Function name must start with a capital or “s:”: rc:syncTree()
    line 82:
    E117: Unknown function: rc:isNERDTreeOpen
    E15: Invalid expression: &modifiable && rc:isNERDTreeOpen() && strlen(expand(‘%’)) > 0 && !&diff
    line 86:
    E193: :endfunction not inside a function
    Press ENTER or type command to continue

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.