old-www/LDP/LG/issue29/kahn.html

224 lines
9.3 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Revisiting VIM LG #29</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; OSF1 V4.0 alpha) [Netscape]">
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<CENTER>
<H1>
<FONT FACE="Arial,Helvetica">Revisiting VIM</FONT></H1></CENTER>
<CENTER><FONT FACE="Arial,Helvetica"><FONT SIZE=+1>
by <a href="mailto:kahn@zk3.dec.com">Andy Kahn</a></FONT></FONT></CENTER>
<CENTER><FONT FACE="Arial,Helvetica"><FONT SIZE=+1>April 29th, 1998</FONT></FONT></CENTER>
<HR>
<CENTER><FONT FACE="Arial,Helvetica">&nbsp;</FONT></CENTER>
<FONT FACE="Arial,Helvetica">Vim stands for "VI Improved", and certainly,
it a very much improved version of the old text editor, vi. It's been a
while since the gazette had an article on vim (over a year to be exact!),
and a lot has changed since then, including a major version release. I
decided to cover some of the new features (as well as some older features)
that I find extremely useful in vim, but not in vi.</FONT>
<BR>
<H3>
<FONT FACE="Arial,Helvetica">Features</FONT></H3>
<FONT FACE="Arial,Helvetica">First of all, let me just run down some of
the big features of the latest version of vim:</FONT>
<BLOCKQUOTE>
<LI>
<FONT FACE="Arial,Helvetica">Syntax highlighting</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">Win32 GUI version</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">BeOS version, including GUI</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">MacOS GUI version</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">VMS version</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">Built-in scripting language</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">Perl and Python support</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">Unlimited undo</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">Multiple windows</FONT></LI>
<LI>
<FONT FACE="Arial,Helvetica">...and a ton of other good stuff</FONT></LI>
</BLOCKQUOTE>
<H3>
<FONT FACE="Arial,Helvetica">Syntax highlighting</FONT></H3>
<FONT FACE="Arial,Helvetica">Personally, I found the syntax highlighting
to be one of the most useful features of vim. Syntax highlighting (or coloring,
as some may call it), colors text according to their attributes. For editing
code, this allows you to have different colors for commented text, keywords,
numbers, etc. You may not think much of it, but believe me, after staring
at code for long periods of time, all the text on the screen starts looking
pretty much the same. It certainly helps to have some color differentiate
between actual code, and comments in the code! A picture is worth a thousand
words, so here's a screen shot of my vim setup editing main.c from the
vim source:</FONT><BR>
<BR>
<CENTER><IMG SRC="./gx/kahn/vim_syntax_highlighting1.gif" ></CENTER>
<P><FONT FACE="Arial,Helvetica">You may notice the curious string on the
very first line of the file: "</FONT><TT>vi:set ts=8 sts=4 sw=4:</TT><FONT FACE="Arial,Helvetica">"
This is just a little formatting shortcut. If you write code that other
people may look at and/or edit, if they also use vim, then the code will
be properly indented as you intended it to be! This is just like the magic
strings people use in emacs: "</FONT><TT>-*- Mode: C++; tab-width: 4; indent-tabs-mode:
nil; c-basic-offset: 4 -*-</TT><FONT FACE="Arial,Helvetica">" to make indentation
look consistent.</FONT><br>
<H3>
<FONT FACE="Arial,Helvetica">Gui versions</FONT></H3>
<FONT FACE="Arial,Helvetica">As for all the wonderful GUI versions of vim,
here's a screenshot I found at <A HREF="http://polder.ubc.kun.nl/~rhialto/be/vim-5.0s-screen1.gif">http://polder.ubc.kun.nl/~rhialto/be/vim-5.0s-screen1.gif</A>
showing off the BeOS version:</FONT>&nbsp;<BR>
<BR>
<CENTER><IMG SRC="./gx/kahn/vim-5.0s-screen1.gif" ></CENTER>
<P><FONT FACE="Arial,Helvetica">Here is a BIG screenshot of the Unix version
of vim with four different looks (vim in an xterm, vim using Athena, vim
using Athena with Xaw3d, and vim using Motif (for Linux users, Vim also
works with Lesstif)). Click on the image for the full size version:</FONT>&nbsp;<BR>
<BR>
<CENTER><A HREF="./gx/kahn/vim_big.gif"><IMG SRC="./gx/kahn/vim_big-small.gif" ></A></CENTER><br>
<CENTER><FONT FACE="Arial,Helvetica"></FONT></CENTER>
<FONT FACE="Arial,Helvetica">There are plenty more screenshots <A HREF="http://www.vim.org/pics.html">here</A>.</FONT><br>
<H3>
<FONT FACE="Arial,Helvetica">Built-in Scripting</FONT></H3>
<FONT FACE="Arial,Helvetica">The built-in scripting language is a small
language (as opposed to Perl and Python) that let's you do some simple
things in your vim startup file (.exrc or rather, .vimrc). For example,
the simplest thing to do is to check for a version or feature:</FONT> <PRE>
<TT> if version >= 500
" Switch on syntax highlighting.
syntax on
if has("cscope")
set csexec=/usr/local/bin/cscope
set csto=0
set csta=1
set csverb=0
cs add cscope.out
set csverb=1
else
map ^] g^]
endif
endif
</TT></PRE><br>
<H3>
<FONT FACE="Arial,Helvetica">Visual Text Selecting</FONT></H3>
<FONT FACE="Arial,Helvetica">A feature which is present even in the previous
version of vim that I use frequently is its "Visual" capability. By hitting
"v" when in command mode, you can highly lines and words and then perform
just about any normal vim operation on the selected text! This includes,
deleting, copying, pasting, running more ":ex" commands, and my favorite,
reindenting. For example, let's say I highlighted the following code:</FONT>&nbsp;<BR>
<BR>
<CENTER><IMG SRC="./gx/kahn/vim_visual1.gif" ></CENTER>
<P><FONT FACE="Arial,Helvetica">If I hit ">" (that's the greater-than sign,
or Shift-.), the result will look like this:</FONT>&nbsp;<BR>
<BR>
<CENTER><IMG SRC="./gx/kahn/vim_visual2.gif" ></CENTER>
<P><FONT FACE="Arial,Helvetica">Or if I were to hit "&lt;" (the less-than
sign, or Shift-,), I get this result:</FONT>&nbsp;<BR>
<BR>
<CENTER><IMG SRC="./gx/kahn/vim_visual3.gif" ></CENTER>
<P><FONT FACE="Arial,Helvetica">If I really wanted to, I could highlight
the entire function, and run then run it through the "indent" program:</FONT>&nbsp;<BR>
<BR>
<CENTER><FONT FACE="Arial,Helvetica">Before:<p><IMG SRC="./gx/kahn/vim_visual4.gif" ALIGN=CENTER></A>&nbsp;&nbsp;<p>
After:<p></FONT><IMG SRC="./gx/kahn/vim_visual5.gif" ALIGN=ABSCENTER></CENTER>
<CENTER>&nbsp;</CENTER><br>
<H3>
<FONT FACE="Arial,Helvetica">C and C++ tags</FONT></H3>
<FONT FACE="Arial,Helvetica">Another feature programmers will find handy
is vim's ability to deal with multiple tags. Vim comes with "Exhuberant
Ctags", and with it, you can store multiple definitions in the same tags
file. Once in vim, you can do use ":tselect" or ":tjump" on a tag, and
vim will present to you a list of the multiple tag entries. Just select
from the list, and vim will take you there as it normally would with a
single tag entry!</FONT><br>
<H3>
<FONT FACE="Arial,Helvetica">There's More!</FONT></H3>
<FONT FACE="Arial,Helvetica">Of course, I could go on and on about all
the little (as well as big!) things that make vim such a great editor.&nbsp;
But I&nbsp;won't bore you with the details. :)&nbsp;&nbsp;You can go read
about them yourself on vim's homepage:&nbsp;<A HREF="http://www.vim.org">www.vim.org</A>.&nbsp;
There's plenty of new things being worked on and added all the time, including
more features in the various GUI versions (contact me if you are interested
in doing a GTK&nbsp;and/or a QT version!), ports to other platforms (including
the Amiga), and other nifty features.</FONT><FONT FACE="Arial,Helvetica"></FONT>
<P><FONT FACE="Arial,Helvetica">There are certainly a lot of text editors
out there, and if you're a vi user, you should definitely consider using
vim if you aren't doing so already!</FONT><br>
<hr>
<FONT FACE="Arial,Helvetica">
Andy works at Digital Equipment Corporation doing
Digital Unix filesystems kernel development.
He thinks he's just hacking away at more and more C code,
and in his copious spare time, he hacks on lots of other
things, including all the trees in his neighborhood.
Feel free to send him
<a href="mailto:kahn@zk3.dec.com">email</a>.
</FONT><br>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1998, Andy Kahn <BR>
Published in Issue 29 of <i>Linux Gazette</i>, June 1998</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./coldiron.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./richardson.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->