<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Indelible Ink</title>
 <subtitle>Fresh Ink (Vim)</subtitle>
 <link href="http://www.indelible.org/feeds/ink/vim.xml" rel="self"/>
 <link href="http://www.indelible.org/ink/" rel="alternate"/>
 <updated>2012-04-25T13:32:21-07:00</updated>
 <id>http://www.indelible.org/ink/</id>
 <author><name>Jon Parise</name></author>
 <rights>Copyright 1999-2012 by Jon Parise. All rights reserved.</rights>

 
   
 

 
 <entry>
   <title>Vim Color Schemes</title>
   <link href="http://www.indelible.org/ink/vim-colorschemes/"/>
   <updated>2009-04-21T00:00:00-07:00</updated>
   <id>http://www.indelible.org/ink/vim-colorschemes</id>
   <author><name>Jon Parise</name></author>
   <category term="vim" />
   <content type="html">&lt;p&gt;The &lt;a href=&quot;http://www.vim.org/&quot;&gt;Vim&lt;/a&gt; text editor supports highly-configurable color schemes which build
upon the editor's rich syntax highlighting system.  The stock Vim distribution
includes a number of color schemes, and many more are available from the &lt;a href=&quot;http://www.vim.org/scripts/script_search_results.php?keywords=&amp;amp;script_type=color+scheme&amp;amp;order_by=rating&amp;amp;direction=descending&amp;amp;search=search&quot;&gt;Vim
Scripts repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Color scheme definitions are simply normal Vim scripts that live in the
&lt;code&gt;colors/&lt;/code&gt; directory of the Vim runtime hierarchy (see &lt;code&gt;:help runtimepath&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Color schemes are loaded using the &lt;code&gt;:colorscheme&lt;/code&gt; command.  The scheme's name
is determined by the filename of its script file (minus the &lt;code&gt;.vim&lt;/code&gt; extension).
For example, to load the stock &lt;em&gt;blue&lt;/em&gt; color scheme (which is defined by the
&lt;code&gt;colors/blue.vim&lt;/code&gt; script):&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    :&lt;span class=&quot;k&quot;&gt;colorscheme&lt;/span&gt; blue
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Creating Color Schemes&lt;/h2&gt;

&lt;p&gt;Creating a custom color scheme is quite easy.  Start by creating a new Vim
script file in the &lt;code&gt;colors/&lt;/code&gt; directory based on the name of the new scheme.
Start the script with the following commands:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dark&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;quot;or light&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;highlight&lt;/span&gt; clear
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; exists&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;syntax_on&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;syntax&lt;/span&gt; reset
    &lt;span class=&quot;k&quot;&gt;endif&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; g:colors_name &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;quot;example&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;These commands will reset the syntax highlighting system to its default state.
Note that some color scheme scripts might prefer a light background, so that
first line should be changed accordingly.  (&lt;code&gt;highlight clear&lt;/code&gt; uses the
&lt;em&gt;background&lt;/em&gt; value, so &lt;em&gt;background&lt;/em&gt; must be set first.)&lt;/p&gt;

&lt;p&gt;The final line sets the global &lt;code&gt;colors_name&lt;/code&gt; variable to the scheme's name
(&lt;em&gt;example&lt;/em&gt;, in this example).&lt;/p&gt;

&lt;p&gt;The rest of the script defines the color scheme itself.  This is accomplished
primarily through the &lt;code&gt;highlight&lt;/code&gt; (or &lt;code&gt;hi&lt;/code&gt;) command.  Each &lt;code&gt;highlight&lt;/code&gt; command
sets the colors for a single syntax group.  Setting the colors for the
&lt;em&gt;Comments&lt;/em&gt; group might look like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    &lt;span class=&quot;nb&quot;&gt;hi&lt;/span&gt; Comment ctermbg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;black ctermfg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;darkgrey guibg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;#000000&lt;/span&gt; guifg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;#777777&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To see the full list of Vim's syntax groups (along with their current
highlight settings), run the following command from within the editor:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    :source $VIMRUNTIME&lt;span class=&quot;sr&quot;&gt;/syntax/&lt;/span&gt;hitest.&lt;span class=&quot;k&quot;&gt;vim&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Testing Runtime Features&lt;/h2&gt;

&lt;p&gt;Because the color scheme is simply a Vim script, you can conditionalize the
definitions based on various runtime values.  The presence of the
&lt;code&gt;gui_running&lt;/code&gt; feature indicates that the Vim GUI is running, for example:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; has&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;gui_running&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;        &amp;quot; GUI colors&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;        &amp;quot; Non-GUI (terminal) colors&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;And the terminal's color range -- the number of available colors -- can be
queried via the &lt;code&gt;&amp;amp;t_Co&lt;/code&gt; variable:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &amp;amp;&lt;span class=&quot;nb&quot;&gt;t_Co&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;255&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;        &amp;quot; More than 256 colors are available&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Additional Configuration&lt;/h2&gt;

&lt;p&gt;Color scheme scripts can support basic configuration using global variables.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; exists&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;g:example_force_dark&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dark&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The user should set this variable in his &lt;code&gt;.vimrc&lt;/code&gt; file before loading the
color scheme script.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; g:example_force_dark &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;colorscheme&lt;/span&gt; example
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;(Global variables can be &quot;unset&quot; using the &lt;code&gt;unlet&lt;/code&gt; command.)&lt;/p&gt;
</content>
 </entry>
 
 
</feed>

