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.
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?
I made this if anyone cares: https://github.com/tiagofumo/vim-nerdtree-syntax-highlight
@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
Most helpful comment
I have been using this for a while now:
added on orignally from: https://github.com/scrooloose/nerdtree/issues/201#issuecomment-9954740