What is VI?

VI is a text editor. Here "VI" refers to the original "vi" as well as its many free clones. The name "vi" comes from "Visual Editor", and was written by Bill Joy (now Chief Scientist at Sun Microsystem) in the original Berkeley Unix development. The clone which I really like is "GVIM" from Bram Moolenaar, which is a GUI-enhanced version of "VIM".

Why VI?

First, I answer a more general question: the main issue about editor choice is, in my opinion, a choice between WYSIWYG editors and key-board based (KBB) editors. VI is an example of a KBB editor (but see below). Once you are convinced of that KBB editor should be part of your skill set, you can look in the web to find arguments for why VI is possibly better than other KBB editors (the other choice of the people is EMACS).

Now WYSIWYG editors are popular because of its small learning curve, but it comes at a great price -- you have to coordinate your eye with your hand in editing. Moreover, your hand has constantly to switch mode between keyboard entry and mouse actions -- a switch that slows you down greatly.

The power of KBB editors is that everything can be done from the keyboard. It means that you can issue very powerful editing commands directly (while WYSIWYG editors would need to pre-compile such macros into menu choices, etc). You can do this while looking away and saying "Look, Ma! No eyes!".

Most adults have invested some effort at learning to touch type -- KBB editors becomes a super-fast tool in the hand of such typists.

Next, among the KBB Editors, the main choice is between vi-based editors versus emacs. My two reasons for favoring vi-based editors is that (1) generally, you use fewer key strokes to accomplish any task, and (2) it is builtin knowledge of basic properties of text files (e.g., concept of words, lines, paragraphs). Emacs has powerful macro features, but vim is catching up on these. Here is a quote from the VIM homepage:

[2004-11-17] The Linux Journal magazine does a Readers' Choice Award every year. For the fourth time in a row Vim was selected the favorite text editor! Vi and clones came second, GNU Emacs third. You can read this and the results in other categories in the press release.

NOTE: The dichotomy between WYSIWYG vs. KBB editors is perhaps blurring. Many KBB editors are acquiring GUI-based capabilities that gives have new features that is traditionally associated with WYSIWYG editors. Thus, GVIM is such a GUI-enhanced version of VIM.

File Names in Cygwin Environment

SUPPOSE you have a file named "profile" under C:/cygwin/etc, how should you invoke gvim on it?
		> gvim /c/cygwin/etc/profile
		> gvim /etc/profile
		> gvim /cygdrive/c/cygwin/etc/profile

		> cd /cygwin/etc
		> gvim profile
		> gvim c:/cygwin/etc/profile
		> gvim "c:/cygwin/etc/profile"

		(The use of double quotes is useful if the file
		name has funny characters like space)

Abbreviation and auto-completion

There are two Auto-Completion features in Gvim: The first is basically abbreviations:
	If you put into your .vimrc file the following line

		:ab ci Courant Institute

	then in the insertion mode, after you have typed
	the string "ci" and it is followed by a tab, return
	or space or double quote or some other "white space" chars
	(unclear what else),
	the string "Courant Institute" will replace the "ci".  But
	be careful -- from now on, as you may have more trouble
	than you want with this feature when your abbreviation
	is as short and common as "ci".  You will have to learn
	tricks to work around unintended completions...

	Of course, the right solution is to make sure that the
	abbreviation contains some unlikely sequence in ordinary
	text, like "qq_", and to use this in all your abbreviations:

		:ab qq_ci Courant Institute
The other Auto-completion feature is based on words already in the current text.
	Suppose that you are in insertion mode, and your
	mouse in placed at a position "X" in the following

	    ...Integer ... X ... Integral ...

	and you started to type "Int".   If you now type control-n,
	the string "Int" would be completed to "Integral" as
	the word "Integral" is found in the buffer AFTER
	your current position.  If you type "control-p" instead,
	the string "Int" would be completed to "Integer" as that
	word is found in the buffer BEFORE your current position.
	(So, control-n means "next" and control-p means "prev").
	If there are multiple choices of words, you will be
	presented with the list of words.   You can do "control-n"
	or "control-p" to move through this list.

Environment Variables

The environment variable VIM is a path prefix used by gvim.

E.g., Syntax features in gvim is very useful. If you turn this feature on in your .gvimrc file, (with the line "syntax on"), then gvim would look for a file named ${VIM}/syntax/syntax.vim.

So, what should VIM be set to? In my .bashrc file, I have

	export VIM=~/.vim

where .vim is a hidden directory for vim related files.

REMARK: to get this to work in cygwin, that is all you need to do. But in my solaris environment, I copy a bunch of files from cygwin into ~/.vim/syntax (e.g., colortest.vim, cterm.vim, dircolors.vim, eterm.vim, hitest.vim, manual.vim, nosyntax.vim, syncolor.vim, synload.vim, syntax.vim, terminfo.vim, texinfo.vim, texmf.vim, tex.vim) Also copied the following files into ~/.vim (e.g., delmenu.vim, evim.vim, filetype.vim, ftoff.vim, ftplugin.vim, indent.vim, makemenu.vim, menu.vim, optwin.vim, scripts.vim, synmenu.vim).

Another problem: all these *.vim files were in dos format. To convert a file FN into unix format, use

	          tr -d '\15\32' < $FN > $FN.MYTEMP
		  mv $FN.MYTEMPT $FN
Of course, you ought to write a shell script that iterates over this.

Feedback? Chee Yap