« How should the church answer the MySpace revolution? | Main | Javascript closures for dummies »
February 21, 2007
Vim syntax files and highlighting
For about the 4th time, I've wasted an hour trying to figure out why my highlighted searches in vim would highlight the searched for phrase with white text on a yellow background; which is virtually unreadable. Since I work on about 4 different computers, I usually just scp my .vimrc to each computer and I'm good to go, however, the search highlighting problem would always reappear when I starting to use a new host.
I use vim with a black background. In the past, I've put the following command in the file .vim/after/syntax.vim:
highlight Search term=reverse ctermfg=0 ctermbg=3 guibg=Yellow
Vim will source any files in the after directory when it's done doing all of the other normal runtime sourcing. With the above command, my searches would now be highlighted with black text on a yellow background.
When troubleshooting syntax issues, I've found the following commands to be eminently helpful.
:highlight - will show you all of the defined highlight groups and with a sample of what syntax
highlighted text will look like when applied. It also gives you the definition string for each group.
:help syntax (gives you all you need to know about syntax highlighting)
:help group-name, shows you some of the most common syntax groups and if syntax highlighting is working properly, what each group looks like with your current syntax profile.
In order to make this fix a bit more portable, I took the line from .vim/after/syntax.vim and put in in my .vimrc. I'm not sure why I didn't think of putting it there in the first place.
If you're curious about the if statement, it just means, the terminal has more than 2 colors, or is gvim. You can read more output codes like &t_Co (number of colors) with
:help terminal-options
Posted by mark at February 21, 2007 2:49 PM Subscribe (FeedBurner)
Comments
thanks mark,
this has helped figure a lot of things out today in the vim world.
Posted by: andrew e. at August 13, 2007 7:20 PM
thanks mark,
this has helped me figure a lot of things out today in the vim world.
Posted by: andrew e. at August 13, 2007 7:20 PM