Localized color schemes
From Vim Tips Wiki
Tip 231 Previous Next Created: April 5, 2002 Complexity: basic Author: Salman Halim Version: 6.0
I frequently like to edit multiple files in the same vim session. however, if I come into vim from another window I frequently hit 'i' and start typing in whatever buffer is currently being used -- this is often the wrong one (requires <Esc>, undo, go the other buffer and . to redo).
One way to work around this for me is to use a different color scheme depending on what file I'm working on:
au BufEnter * if (exists("b:colors_name")) | let b:current_colors=colors_name
\| execute "colorscheme " . b:colors_name | endif
au BufLeave * if (exists("b:current_colors")) | execute "colorscheme " . b:current_colors | endif
If you define b:colors_name with a particular color scheme name, then the above autocommands will switch to that colorscheme when you enter that window and will return to the original color upon departure.
Inside ftplugin/java.vim, for example, I might have b:colors_name set to 'morning', causing all java files to have a distinguishing color scheme.
