Saturday, May 28, 2005

Dehighlighting Vim

Although I'm a big fan of the one True Editor , I frequently use a version of vi for editing small files. The vi editor that comes with Fedora is an "enhanced" version of vim. (Don't worry about what the acronyms mean, I gave up a long time ago.) vim has some useful features that go above and beyond vi. For example, vim supports context sensitive syntax highlighting. Thus, if I edit the prototype Fortran program, using

$ vi hello.f

My xterm window comes up looking like this:

      program hello
      write(*,*) 'Hello World!'
      stop ' Goodbye'

with keywords highlighted. This behavior is default in Fedora, but you can select it by creating (or editing) the file .vimrc in your home directory to include the line

syntax on

This is a good thing. However, there's also an annoying thing in the default Fedora Core setup of vim. I've resently been editing a file with a lot of numbers which include exponents. One way to search for these numbers is to search for the exponent symbol, "E". In that case vim gives you something like this:


Actually, it's more annoying than that. The E is actually highlighted with a yellow background, but I didn't want to figure out how to show that right now.

This annoying behavior can be corrected by adding:

set nohlsearch

to the .vimrc file.

One more thing: I usually prefer case-insensitive searches, so that searching for "bob" matches "Bob" and "BOB" as well. That requires the line:

set ignorecase

There's a lot more you can do with .vimrc. Here's a sample. I'm satisfied with these simple tweaks, however.


Abby Taylor said...

How weird. I was just about to post the SAME THING over at falafel sex. Spooky.

rcjhawk said...

Hey, we have to post a Linux tip once in awhile...