16 August 2000
Richard
R. Klemmer has been using OS/2 since 1995. He currently works as a programmer
for the Department of Agriculture. In his spare time he works for WebTrek L.L.C,
an Internet consulting company.
If you have a comment about the content
of this article, please feel free to vent in the OS/2 eZine discussion
forums.
|
|
VIM for OS/2
VIM, or Vi IMproved, is a clone of the
Vi editor, one of the standard Unix text editors. VIM has been ported to a great
many operating systems, including, of course, OS/2. First, a little background.
The source code for the vi editor is copyrighted, which is why VIM is a clone of
vi. Originally VIM stood for Vi IMitation , but there have been some many improvements
over the standard vi that the name was changed. VIM includes all the commands of
the vi editor and many new ones. It is a text mode editor, especially useful for
programmers or anyone who needs to edit plain text files on a regular basis. VIM
was written by Bram Moolenaar. Paul Slootman wrote the OS/2 port. VIM was ported
using the EMX libraries so you will need to have the EMX runtime libraries installed
on your system. The README states that you need version 0.9b, but you should get
the latest which is, I believe, 0.9d Fix 2. You can get the EMX runtime from Hobbes
- http://hobbes.nmsu.edu.
Getting VIM
The VIM home site is located at http://www.vim.org. There are a list of download sites
there where you can get the OS/2 binaries for VIM. You will need two files, the
runtime and the binaries. The latest version is 5.7, so the files should be named
vim57rt.zip for the runtime and vim57os2.zip for the binaries. Unzip these files
in the root directory of the drive you wan to install VIM on and they will create
a directory structure similar to this: x:\vim\vim57, where "x" is the
drive letter in which you installed VIM.
If you want to run VIM from anywhere
on your system, you need to add the directory to your path statement. The readme
file also states that you can put the executable, vim.exe, anywhere on your system,
but if you do you need to set the VIM environment variable in your config.sys file
like this "SET VIM=x:\vim\vim57." Even though I didn't move the executable
from the distribution location, I found that I needed to set the VIM environment
variable for VIM to work properly.
VIM is a highly configurable application.
Configuration is done with the vimrc file. There is an example distributed with
the OS/2 port named vimrc_example.vim. You will need to copy this to a file name
.vimrc, make sure to include the preceding period in the name of the file. If you
are running this off of a FAT system, you can name the file _vimrc, with the underscore
replacing the period. The configuration options are too numerous to go into hear.
Your best bet is to read through the documentation and see what is possible, then
experiment and find the options that you like and add them, or remove them from
your .vimrc file.
One problem I ran into was how VIM
dealt with terminal types. If you do not have anything set for your systems TERM
environment variable, then VIM will default to os2ansi for a term type. This is
okay, but if you DO have SET TERM={something} in your config.sys, then you may run
into some issues depending on what terminal type you are using. I have SET TERM=ANSI
in my config.sys and when VIM starts up, the background is a strange green color
that makes reading the test very difficult. I fixed this by adding "set term=os2ansi"
to my .vimrc file.
Using VIM
If you've never used vi or VIM before,
then it may take a little getting used to. VIM has various modes in which it operates.
The two that you will use most often are Normal or Command mode and Insert mode.
VIM starts up in normal mode, which allows you to execute various commands, such
as deleting or copying text, searching the file and saving/exiting the file. Insert
mode lets you type in text. There are various ways to enter Insert mode from Normal
mode. The basic ways to enter Insert mode are by typing "i" to start inserting
text at the current cursor location, "I" to start insert at the beginning
of the current line, "a" to start inserting after the current cursor location,
"A" to start at the end of the current line, "o" to insert a
line below the current line and "O" to insert a line above the current
line. To return to Normal mode, hit the Escape (ESC) button.
When in Normal mode, you issue some
of the commands by typing a colon, and then a command. For example, to exit VIM
type ":q". When you type the colon, the cursor will be position at the
bottom of the window.
Other useful commands to use while
in Normal mode are listed below:
:w Save (write) the file.
:wq Save then quit
:q! Quit without saving changes. (:q will not work if you've modified the file)
CTRL-F Scroll forward in the file approximately one screen length
CTRL-B Scroll backward in the file one screen length
CTRL-D Scroll forward approximately one-half screen length.
CTRL-U Scroll backward in the file one screen length
/ {text} Search for next occurrence of {text} in file.
? {text} Search backward for previous occurrence of {text} in file.
w Move forward one word
x Delete current text at cursor
X Delete text before cursor (similar to backspace in another editor)
dd Delete current line (and place into buffer)
yy Copy (yank) current line into buffer.
p Place (paste) contents of buffer into file.
With the last commands, starting
with "w", you can type a number before the command to execute that command
a particular number of times. For example, typing "2w" will move forward
two words. Typing "2dd" will delete two lines. You can also combine some
commands, such as "w" and "d". Typing "dw" will delete
one word, "2dw" will delete two words, and so forth.
There is a tutorial file that comes
with the distribution, located in a sub-directory call "tutor." There
should be a file named "tutor." Copy this to another name, since the tutorial
will have you editing this file, and then load it into VIM by typing "vim tutor"
at the command prompt. This should give you some practice using the basic commands
in VIM.
VIM improvements
The list of benefits of using VIM
over Vi fills up a great deal of space on www.vim.org. First and foremost, since
the Vi source is copyrighted, as far as I know there isn't a version for OS/2. I'll
quickly go into a couple of the other benefits.
Syntax highlighting
Maybe it's because I spent years
looking at green text on IBM mainframes, or maybe it's just because I get excited
by programs that look like Christmas decorations, but I have a tough time living
without syntax highlighting. VIM provides this for just about any programming language
you can thing of, including REXX, C/C++, Java, PERL and PHP. It also provides syntax
highlighting for HTML files. The example vimrc file will enable syntax highlighting
for any TERM that will support colors, which includes os2ansi. You can also enable
and disable syntax highlighting from within the file by typing ":syntax on"
to enable and ":syntax off" to disable. Below is a screenshot of VIM editing
a php script.
Multiple window support
VIM allows you to split the window
to have two separate views within vim. You do this by issuing the ":split"
or just ":sp" command. If you have a file loaded into VIM when you do
this, the file will be opened in both windows. This is good if you want to look
at different sections of a large file. To move between screens type "CTRL-Ww."
That is, press the control and the W key at the same time, then press the W again.
You can also open a different file in the second window issue the command ":e
{filename}." This is also the normal way to load a file into VIM. You can load
a file when you issue the split command by typing ":sp {filename}." You
can increase the size of the current split window by typing "N CTRL-W +"
where "N" is the number of lines you wish to increase the window. If you
leave a number off it will just increase the size by one line.
Why use VIM?
That's a good question. There are
a number of good shareware editors out there for OS/2. I've purchased frequently
use a couple of them myself. And, of course, there is the Enhanced Editor, or EPM,
that comes with OS/2. This is extremely powerful and configurable. However, if you
need to switch between Unix systems and OS/2, it's always nice to be able to use
the same tools on both systems. It also gives you experience with tools that are
prevalent on Unix systems, in case you may be working on one in the future. Also,
if you ever have to telnet into your OS/2 system, you won't be able to use any of
the Presentation Manager programs, such as EPM, so you will need at text mode program
to edit any files. You can use TEDIT which comes with OS/2, but I think you'll find
that this pales in comparison to what you can to with VIM.
Is that all?
Unfortunately, I can't even come
close to scratching the surface of what you can do with VIM. The best way to learn
is to get a copy of it and start playing.
|