Skip to Content
Learning the vi and Vim Editors, 7th Edition
book

Learning the vi and Vim Editors, 7th Edition

by Arnold Robbins, Elbert Hannah, Linda Lamb
July 2008
Beginner
492 pages
16h
English
O'Reilly Media, Inc.
Content preview from Learning the vi and Vim Editors, 7th Edition

What’s Your Favorite Color (Scheme)?

Let’s begin with the simplest of configurations. We’ll customize our environment to a color scheme we prefer. This is simple, and uses one of the basics of Vim scripts, the simple Vim command.

Vim ships with 17 customized color schemes. You can choose and activate a color scheme by putting the colorscheme command in your .vimrc or .gvimrc file. A favorite “understated” color scheme of one author is the desert scheme:

colorscheme desert

Put a colorscheme like that in your configuration file, and now every time you edit with Vim you will see your favorite colors.

So our first script is trivial. What if your tastes for your color scheme are more complex? What if you like more than one color scheme? What if the time of day correlates to your preferences? Vim scripts easily let you do this.

Note

Choosing an alternate color scheme depending on the time of day may seem trite, but maybe not as much as you may think. Even Google changes the colors and tone of your iGoogle home page throughout the day.

Conditional Execution

One of the authors likes to divide the day into four partitions, each with its own dedicated color scheme:

darkblue

Midnight to 6 a.m.

morning

6 a.m. to noon

shine

Noon to 6 p.m.

evening

6 p.m. to midnight

We’ll build a nested if...then...else... block of code for this purpose. There are a couple of different syntaxes you can use for this block. One is more traditional, with an explicitly laid out syntax:

ifcond expr
  line of vim code
  another line of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning the vi and Vim Editors, 8th Edition

Learning the vi and Vim Editors, 8th Edition

Arnold Robbins, Elbert Hannah
Mastering Vim

Mastering Vim

Ruslan Osipov
Mastering Vim

Mastering Vim

Damian Conway
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9780596529833Errata Page