History
Article Edit this page Discussion

Localized color schemes

From Vim Tips Wiki

Jump to: navigation, search

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.

[edit] Comments

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Localized color schemes"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation