sponsor Vim development Vim logo Vim Book Ad

basic Tip #53: Better colors for syntax highlighting

 tip karma   Rating 338/149, Viewed by 14158 

created:   March 18, 2001 12:59      complexity:   basic
author:   Anonymous      as of Vim:   5.7

For syntax highlighting there are two sets of default color
maps: One for a light and another one for a dark background.
If you have a black background, use the following command to
get a better color map for syntax highlighting:

:set background=dark

You have to switch off and on again syntax highlighting to
activate the new color map:

:syntax off
:syntax on

For a detailled description of syntax highlighting refer to

:help syntax.txt

See also the Vim syntax support file: $VIMRUNTIME/syntax/synload.vim

 rate this tip  Life Changing Helpful Unfulfilling 

<<Scrolling synchronously | View a Java Class File Decompiled thru Vim >>

Additional Notes

[email protected], November 10, 2001 23:52
I just checked this in 6.0 and you no longer have to turn syntax off and then back on.
Anonymous, August 10, 2002 5:00
Love is in the air...
[email protected], November 26, 2002 11:53
This function reverses background setting so you can quickly toggle between light and dark .  I use it because I'm often changing my desktop background and use transparent terminals.

:function! ReverseBackground()
:   let Mysyn=&syntax;
:   if &bg;=="light"
:       se bg=dark
:   else
:       se bg=light
:   endif  
:   syn on  
:   exe "set syntax=" . Mysyn
":   echo "now syntax is "&syntax;
:endfunction
:command! Invbg call ReverseBackground()
:noremap <F11> :Invbg<CR>
"
Anonymous, July 10, 2003 20:47
You may also need to change the highlighting to match the new background.  Here's the same macro as before, but toggling the bacground colour of the window as well:

:function! ReverseBackground()
:   let Mysyn=&syntax;
:   if &bg;=="light"
:       se bg=dark
:       highlight Normal guibg=black guifg=white
:   else
:       se bg=light
:       highlight Normal guibg=white guifg=black
:   endif  
:   syn on  
:   exe "set syntax=" . Mysyn
":   echo "now syntax is "&syntax;
:endfunction
:command! Invbg call ReverseBackground()
:noremap <F11> :Invbg<CR>
Anonymous, August 21, 2003 15:31
Mmm... desert... I like that! :-)

https://www.vim8.org/scripts/script.php?script_id=105
[email protected], March 28, 2004 2:26
How do you make :set background=dark permanent ?

[email protected], April 1, 2004 2:16
Just add the line "set background=dark" to your vimrc file (systemwide = /etc/vimrc) !

Regards,
Heiko
[email protected], April 7, 2004 7:41
Just to say I use this line in my vimrc:

map <F11> :let &background; = ( &background; == "dark"? "light" : "dark" )<CR>

That let's me switch backgrounds pretty quickly

jac
Anonymous, June 8, 2004 12:18
Great macro...  I really have to start learning about these macro's in vim.

E.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo