Nerdtree: Allow configuration for multiple highlighting based on file type.

Created on 11 Apr 2015  Â·  17Comments  Â·  Source: preservim/nerdtree

Similar to the red highlighting on read-only files, it would be nice if you could configure a different colour highlighting based of the file type & extension. If anyone has found a way to do this manually I'd love to hear how.

Most helpful comment

I have been using this for a while now:

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

call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '#151515')
call NERDTreeHighlightFile('ini', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('md', 'blue', 'none', '#3366FF', '#151515')
call NERDTreeHighlightFile('yml', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('config', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('conf', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('html', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('styl', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('coffee', 'Red', 'none', 'red', '#151515')
call NERDTreeHighlightFile('js', 'Red', 'none', '#ffa500', '#151515')
call NERDTreeHighlightFile('php', 'Magenta', 'none', '#ff00ff', '#151515')

added on orignally from: https://github.com/scrooloose/nerdtree/issues/201#issuecomment-9954740

All 17 comments

I have been using this for a while now:

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

call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '#151515')
call NERDTreeHighlightFile('ini', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('md', 'blue', 'none', '#3366FF', '#151515')
call NERDTreeHighlightFile('yml', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('config', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('conf', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('html', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('styl', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('coffee', 'Red', 'none', 'red', '#151515')
call NERDTreeHighlightFile('js', 'Red', 'none', '#ffa500', '#151515')
call NERDTreeHighlightFile('php', 'Magenta', 'none', '#ff00ff', '#151515')

added on orignally from: https://github.com/scrooloose/nerdtree/issues/201#issuecomment-9954740

Thanks, this looks like exactly what I needed. I should be putting this anywhere in ~/.vim/syntax/nerdtree.vim right?

Mine is just in my vimrc

Thanks again, this seems to be working. Are you using console vim or gvim? For some reason the colours aren't corresponding with what I am setting.

Help, i'm getting this

Se ha detectado un error al procesar function NERDTreeHighlightFile:
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight jade ctermbg=none ctermfg=green guibg=#151515 guifg=green
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match jade #^\s\+.*jade$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight ini ctermbg=none ctermfg=yellow guibg=#151515 guifg=yellow
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match ini #^\s\+.*ini$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight md ctermbg=none ctermfg=blue guibg=#151515 guifg=blue
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match md #^\s\+.*md$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight yml ctermbg=none ctermfg=yellow guibg=#151515 guifg=yellow
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match yml #^\s\+.*yml$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight config ctermbg=none ctermfg=yellow guibg=#151515 guifg=yellow
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match config #^\s\+.*config$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight conf ctermbg=none ctermfg=yellow guibg=#151515 guifg=yellow
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match conf #^\s\+.*conf$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight json ctermbg=none ctermfg=yellow guibg=#151515 guifg=yellow
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match json #^\s\+.*json$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight html ctermbg=none ctermfg=yellow guibg=#151515 guifg=yellow
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match html #^\s\+.*html$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight styl ctermbg=none ctermfg=cyan guibg=#151515 guifg=cyan
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match styl #^\s\+.*styl$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight css ctermbg=none ctermfg=cyan guibg=#151515 guifg=cyan
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match css #^\s\+.*css$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight coffee ctermbg=none ctermfg=Red guibg=#151515 guifg=red
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match coffee #^\s\+.*coffee$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight js ctermbg=none ctermfg=Red guibg=#151515 guifg=#ffa500
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match js #^\s\+.*js$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight php ctermbg=none ctermfg=Magenta guibg=#151515 guifg=#ff00ff
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match php #^\s\+.*php$#
lĂ­nea    1
E216: No existe tal evento: nerdtree highlight py ctermbg=none ctermfg=green guibg=#151515 guifg=green
lĂ­nea    2
E216: No existe tal evento: nerdtree syn match py #^\s\+.*py$#

It means: event doesn't exist

Did you make sure to include the function NERDTreeHighlightFile(extension, fg, bg, guifg, guibg) that ryanoasis posted as well?

Yes, i did

Ok, i fixed it replacing filetype with FileType, and it's working now :)

This is pretty great, but is it possible to change the color for folders?

@ryanoasis your script works great to change the color of files, but for the case of executable files, the script does not change the color of those. Is there any way to get around that?

@tiagofumo is there anyway I can install that with Vundle?

@marzzz21 I suppose, yeah. I never used vundle but what I made is like a common extension, so it should work. You will need vim-devicons and nerdfonts for the icons. Checkout the description on repo page.

Thank U! It's useful for me!

Thanks! Works with Vim 8.1

Thx a lot! It is really helpful.

Parsing LS_COLORS would be the dream but my vimscript is nowhere near that level

Was this page helpful?
0 / 5 - 0 ratings