Return to CS Home

Computer Science @ Florida State University
Information for prospective, undergraduate, and graduate students in CS
Students, Alumni, Faculty, & Staff in CS
Job listings and employment resources
Department policies, technical information, and statistics
Access & Usage Policy
Email Information
Java Setup
Dial Up Services
FTP Information
Lab Information
Getting System Help
Unix Help
Misc. Technical Information
Online Man Pages
CS Hardware Information
Web Server Statistics
Repetitive Stress Injury

ACM, CLUE, and other sites related to CS

Search CS


Configuring VIM/GVIM

(last changed Feb 16, 1999)


Introduction

"If you like vi, you'll love vim!". So say the authors of vim, which stands for "vi improved", a modern version of the vi editor. Also available is gvim, a graphical user interface version of vim.

By far the most important new feature offered by vim is syntax coloring (coloring and highlighting of text according to the rules of syntax, for example, coloring blue all comments in your code and printing in bold all programming keywords such as "main, if, for, etc..). This feature can be found in emacs and various MS software developement packages.

If syntax coloring is important to you, and it should be, it is best to stick with (or at least start with) gvim. Since gvim uses a GUI, it is easier to get the color feature working because it does not need to know details about the environment in which you are working (for example, it does not need to know what kind of TERM you are using). In addition, the number of colors which can be displayed on your terminal is limited. The disadvantage of gvim is that you cannot use it remotely, you must be able open the display on the machine you are working on. In some cases this not possible, for example if you are logged on at home using your modem.

For now, only a description of how to configure syntax coloring for gvim will be given. Further instructions on how to configure vim will be posted at some yet undetermined point in the future.

For more information on how to use vim, check out the The VIM (Vi IMproved) Home Page


.gvimrc

The first thing you'll need is a .gvimrc file located in your home directory. This can also be copied to .vimrc. Here is a sample .gvimrc. This is the basic configuration file, it is the file that you modify to customize gvim to look and behave the way you want it to.

To turn on the syntax coloring, you must include the line:

    source ~/.syntax.vim


.syntax.vim

This is the file that defines all of the basic elements of syntax that are found in all languages (note that I have included the "." in front making it a hidden file, this is not the usual convention). For example, the line:

  highlight Comment     term=bold ctermfg=Blue guifg=Blue
specifies that any comment should be bold and colored blue. When you open up a file, gvim looks at the extension and then decides what type of file you are opening. For example if you open a file with a ".cpp" extension

   gvim myprogram.cpp

it assumes you are opening a c++ file. It then parses this file and extracts the comments as defined in the file cpp.vim. It then refers to the .syntax.vim file and looks up what color a comment should be. Therefore by changing the color assigned to comments in the .syntax.vim you will change the color of comments in all languages, c++, perl, java, fortran, html, etc, etc.

Here is a sample .syntax.vim. It too should be placed in your home directory.

The individual syntax files that define particular languages can be found in the directory:

   /usr/local/share/vim/syntax

Syntax files have been written for most of the common languages already, but if you are programming in a language for which a syntax file does not exist you can write your own by using one of these as a prototype.

Here are just few examples of syntax files that have already exist:

   awk.vim	basic.vim
   c.vim	cpp.vi
   csh.vim	html.vim
   java.vim	make.vim
   perl.vim	tex.vim 

It is always a pleasant surprise when you open a file for editing and find that it has been nicely colorized and highlighted for you automatically.


$VIM Environment Variable

In order for the .syntax.vim file to be working correctly, you need to set the $VIM environment variable. If you use the bash shell, place this in your .bashrc file:

   export VIM=/usr/local/share/vim

If you use tcsh, place this in your .tcshrc file:

   setenv VIM /usr/local/share/vim

If you are unsure of which shell you are using, type:

   echo $SHELL

at the unix prompt. Or you can check your entry in the passwd file by typing:

   ypcat passwd | grep -i lastname 

The last item will list what your default shell is. For example, mine looks like:

bismuti:reLmuBPSSj4HA:21841:299:Peter Bismuti:/home/grads/bismuti:/etc/system-bash

I am using the bash shell. If you do not know which shell you have been assigned, you probably have been assigned tcsh by default.



Official Website of Florida State University
Comments and questions should be sent to webmaster@cs.fsu.edu.