function! NERDTreeHighlightFile(extension, fg, bg)
    exec 'autocmd filetype nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension .'$#'
    exec 'autocmd filetype nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:bg .' guifg='. a:fg

Ripped this from a thread on the NERDTree file highlighting stufff.

So real quick, this function is working for all filetypes except for .c files, funnily enough the ones I use the most. I'm new to vim plugins and such though so have mercy lol.

I'm no pro at regex but it looks to me like there aren't any problems in that department.

If someone could figure this out that'd be dope. Thanks.

  • How did you call the function? – muru Dec 15 '15 at 9:06
  • call NERDTreeHighlightFile('c'. 'yellow', 'none') – Kibbles Dec 15 '15 at 9:14
  • 1
    You can edit your post to add information. – muru Dec 15 '15 at 9:15
  • So that's basically how the function is run for all filetypes, the ".h" files get called in the exact same way, (with yellow etc) and they are highlighted properly. – Kibbles Dec 15 '15 at 9:16

Your Answer


Browse other questions tagged or ask your own question.