Nerd Notes

/dev/brain: no space left on device

Making vim syntax highlighting usable

with 13 comments

Someone says vi vi vi is the editor of the beast. He’s right. That’s why I use vim, which is a modern editor, backwards compatible with vi and full of bells and whistles. But, most of all, vim gets things done for me. I’m in love with vim.

On some modern linux distributions, vim comes with syntax highlighting enabled by default. Since you’re a die-hard nerd like me, your terminal window colors scheme is like god meant it to be: with a black background. And, if you really feel nostalgic like me, you may even have gone one step further and you’ve setup green as the foreground color. That’s great, but there’s one thing that makes vim syntax highlighting suck on such a color scheme: it was meant by default to work on a light (read white) background.

My colleagues hate vim’s default color highlighting and they’re tempted all the time to use the old beast: vi, just because it has no color syntax highlighting which makes comments unreadable to say the least. This should get fixed. Enter the gay world with: set background=dark That means, while in vim, enter command mode and type the above command.

Great! The world has suddenly become clearer and you feel an urge to dance to the rhythm of Village People’s YMCA. That is, until you close vim and open it again. Then you’re into Robert Smith mode again. Too bad. We’ve got to fix that too. The recipe is as easy as editing your ~/.vimrc or, better yet, making the change system wide by editing the /etc/vim/vimrc file and adding a couple lines:

syntax on
set background=dark

That’s it. Now, where’s my biker dress?

Advertisements

Written by Mirko Caserta

October 27, 2006 at 7:48 am

13 Responses

Subscribe to comments with RSS.

  1. On Ubuntu edgy (very new distibution) vim cannot do syntax coloring anymore :-(
    It says:
    Sorry, the command is not available in this version: syntax on
    Also in vim :syntax on:
    E319: Sorry, the command is not available in this version

    Madness!! I hate it

    Michael

    January 26, 2007 at 6:47 pm

  2. The solution to your problem is to install vim. If you have that error message, it looks like you have vim installed but you actually don’t. By default, edgy comes with vim-common installed but not vim. vim-common has a vim binary which is actually vi. And, you know, vi is very much different from vim :)

    $ sudo apt-get install vim

    should do it ;)

    mcaserta

    January 26, 2007 at 9:29 pm

  3. “Since you’re a die-hard nerd like me, your terminal window colors scheme is like god meant it to be: with a black background. And, if you really feel nostalgic like me, you may even have gone one step further and you’ve setup green as the foreground color.”

    Right on. This was just what I was looking for – looking at dark blue on black comments just doesn’t work.

    boo

    March 26, 2007 at 9:07 pm

  4. Thanks a bunch…
    I was really getting sick of using gedit just for highlighting…

    thefekete

    March 31, 2007 at 6:42 am

  5. how i can get vim start with syntax highlighting as default?!

    daltin

    April 10, 2007 at 2:21 am

  6. Thanks for the previous comments, I got the highlighting working again.
    About the previous comments, my version of vim is 7.0 (got updated from 6.2 at the same time as Ubuntu from Dapper to Edgy).
    To get this syntax highlighting automatically, just add one line
    syntax on
    in your ~/.vimrc file
    Hope it helps.

    Matthieu

    April 17, 2007 at 8:21 pm

  7. Thanks a lot. Now I can read my comments again! Hurray. Sometimes it’s the simple things that are worth a blog entry and not some RTFM hint!

    Stefan

    May 8, 2007 at 1:47 pm

  8. Thanks, I find this from Google it’s useful :)

    Ozi

    October 8, 2007 at 6:43 am

  9. This looks great for my C++ environment! Thanks!

    Spencer

    July 15, 2008 at 4:42 am

  10. Oh wow. I especially enjoy your use of Gravatar!

    Spencer

    July 15, 2008 at 4:43 am

  11. Thanks for this! I hope you are getting comment notifications on 2.5 year old posts. Exactly what I needed. I have used vim for over a decade and didn’t know about background-dark.

    Now I guess I need to read through your entire blog for more useful stuff.

    Galbinus_Caeli

    January 24, 2009 at 7:15 pm

  12. I want you to show me the the procedure use in making of vim because my teacher gave us as an assignment to submit tommorrow.

    nwiku

    November 24, 2009 at 3:11 pm

  13. Hi! Someone in my Myspace group shared this website with us so I came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers! Great blog and terrific design and style. ckfcbcaebbeb

    Johnd301

    May 16, 2014 at 2:50 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: