HACK HACK BODGE
Following on from a conversation at the Pisa-London.pm Social last night about vim syntax highlighting useful words in perl files like TODO and how it might also be useful to highlight other useful words, like HACK and BODGE, I decided to have a go.
I knew the initial solution would be fairly simple - hack /usr/share/vim/vim72/syntax/perl.vim
.
That seemed to easy, so I investigated a $HOME/.vim/
solution.
Initially I copied the existing perl.vim
into my local directory:
cp /usr/share/vim/vim72/syntax/perl.vim $HOME/.vim/syntax/
edited the perlTodo
line to include the new tokens.
I opened my test file and it worked!
Going Further
I’ve had a long-standing urge to handle tokens followed by an evil colon. I prefer:
# TODO: something shiny
over
# TODO something shiny
To me it looks nicer when it isn’t highlighted.
I further modified the perlTodo
line, from keyword
to match
and included my friend, the colon.
One “:e!
” later and … it worked!
Cleaning Up
I really didn’t want a copy of the entire perl.vim
syntax file.
I took a risk and edited my local copy down to one single line, reloaded my test file and … it did the right thing!
The Solution
To go from:
to:
create $HOME/.vim/syntax/perl.vim
and add the following line:
syn match perlTodo "\<\(TODO\|TBD\|FIXME\|XXX\|HACK\|BODGE\)\:\?\>" contained
Sorted!
chisel++
I need to start digging around in the syntax files myself. This is good inspiration :)
I've gone a step further and added BUG tag.
Right below the "
syn match perlTodo
", I have added this:Then I have modified the "
syn match perlComment
" line as follows:Finally, I have added a new
HiLink
at the bottom of the list:Then if I put BUG (or BUG:) in a comment, it gets highlighted with a red background and white text which really stands out.