{"id":130,"date":"2009-04-04T14:32:02","date_gmt":"2009-04-04T19:32:02","guid":{"rendered":"http:\/\/elegans.uky.edu\/blog\/?p=130"},"modified":"2009-04-04T14:32:02","modified_gmt":"2009-04-04T19:32:02","slug":"256-colors-in-vim-on-os-x","status":"publish","type":"post","link":"http:\/\/jimlund.org\/blog\/?p=130","title":{"rendered":"256 colors in vim on OS X"},"content":{"rendered":"<p>Terminal colors are broken out of the box in OS X terminals.  In part due to a poor OS X terminal implementation, part due to problems with vim.  I try new colorschemes and get strange, random looking results.<\/p>\n<p>After many fruitless searches I finally got 256 colors working in vim in a terminal.  <a href=\"http:\/\/rtlechow.com\/2008\/12\/256-colors-in-vim-inside-screen-in-an-iterm-on-os-x-leopard\/\">This post<\/a> and the GVim site were very helpful.  It turns out that the included Terminal app in OS X only supports 16 colors.  The terminal background can be set to any color which confuses the issue.  The <a href=\"http:\/\/www.vim.org\/scripts\/script.php?script_id=1349\">colortest Perl script<\/a> available on the Gvim site makes this clear.<br \/>\nOS X Terminal colortest:<br \/>\n<a href=\"pics\/colortest_Terminal.png\"><img decoding=\"async\" src=\"pics\/colortest_Terminal_sm.png\" alt=\"colortest run in Terminal\" \/><\/a><\/p>\n<p>The free GNU licensed <a href=\"http:\/\/iterm.sourceforge.net\/\">iTerm<\/a> terminal does support 256 colors.<br \/>\niTerm colortest:<br \/>\n<a href=\"pics\/colortest_iTerm.png\"><img decoding=\"async\" src=\"pics\/colortest_iTerm_sm.png\" alt=\"colortest run in Terminal\" \/><\/a><\/p>\n<p>OK, now the terminal supports 256 colors.  There are still some hoops to jump through to get vi to show colors though.  Most colorschemes are built for gui (using 24-bit RGB colors), so vim needs to be built with gui support.  This can be checked with :echo has(&#8216;gui&#8217;).  It reports 1 for yes, 0 for no.  The vim I had (default or Fink installed) didn&#8217;t have gui support, so I downloaded GVim and copied it over the old vim:<\/p>\n<blockquote><p>cp \/Volumes\/Vim-7.2.148\/Vim.app\/Contents\/MacOS\/Vim \/usr\/bin\/vim<\/p><\/blockquote>\n<p>and now vim has gui support.<\/p>\n<p>I copied \/usr\/share\/vimrc to \/usr\/bin because the downloaded vim didn&#8217;t know to look in \/usr\/share and added a few configuration lines:<\/p>\n<blockquote><p>\n&#8221; Doesn&#8217;t get set right.<br \/>\nset t_Co=256<\/p>\n<p>&#8221; Needed because the new vim doesn&#8217;t know to look in \/usr\/share<br \/>\nset runtimepath=~\/.vim,\/usr\/share\/vim\/vim72_2,\/usr\/bin\/vimfiles,\/usr\/bin,\/usr\/bin\/vimfiles\/after,~\/.vim\/after<br \/>\nlet $VIMRUNTIME=&#8217;\/usr\/share\/vim\/vim72_2&#8242;<\/p>\n<p>syntax on<br \/>\ncolorscheme LightTan\n<\/p><\/blockquote>\n<p>OK, so now 256-color support works and I can set colorschemes.  They still don&#8217;t look right because colorschemes made for the gui don&#8217;t look right on a 256-color terminal.  There&#8217;s a great vim script called <a href=\"http:\/\/www.vim.org\/scripts\/script.php?script_id=2390\">CSApprox<\/a> that converts gui colors to the closest of the 256 colors and makes gui colors look pretty good in a terminal.  Download it, unzip it, and copy files to the vim directory:<br \/>\n<code>sudo cp plugin\/CSApprox.vim  \/usr\/share\/vim\/vim72_2\/plugin<br \/>\nsudo cp autoload\/csapprox.vim \/usr\/share\/vim\/vim72_2\/autoload<\/code><\/p>\n<p>and now when I load colorschemes they look pretty close to what the <a href=\"http:\/\/www.cs.cmu.edu\/~maverick\/VimColorSchemeTest\/\">Vim colorscheme test<\/a> site shows, with the only difference due to font differences.<\/p>\n<p>To get full color support when I log into a linux machine I need to do some more setup.  To get gui support in terminal:<br \/>\nyum install vim-X11<br \/>\nand then add to \/etc\/profile:<br \/>\nalias vi=&#8217;gvim -v&#8217;<br \/>\nand &#8220;source \/etc\/profile&#8221; to enable it.<br \/>\nand add:<\/p>\n<blockquote><p>\nset t_Co=256<\/p>\n<p>if &#038;t_Co == 256<br \/>\n    colorscheme LightTan<br \/>\nendif\n<\/p><\/blockquote>\n<p>to \/etc\/vimrc to force 256-color mode and pick a colorscheme.<\/p>\n<p>I also copied the CSApprox files to \/usr\/share\/vim\/vim70 and now it works when I ssh to this machine as well!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Terminal colors are broken out of the box in OS X terminals. In part due to a poor OS X terminal implementation, part due to problems with vim. I try new colorschemes and get strange, random looking results. After many fruitless searches I finally got 256 colors working in vim in a terminal. This post [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-computers"],"_links":{"self":[{"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=130"}],"version-history":[{"count":0,"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions"}],"wp:attachment":[{"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jimlund.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}