VIM and Progress

VIM Screenshot

Do you use Vi? I use VIM ( Vi IMproved ) for editing a lot of my Progress code. I’m trying to make a point of it these days for editing my text as well. Anyway, there’s a lot of power behind VIM and as you get to know some of it’s tricks and functionality it can become a lot more powerful than your basic Vi installation. So, I thought I’d pull together some of my favourite tips for using VIM with Progress and publish them here.

Autocompletion.


Try this. Open an existing program in VIM and insert the first few characters of a variable, temp-table or procedure name. Now hit CTRL-X followed by CTRL-P. VIM will search back from the current point for the first word beginning with the characters you have entered and use it to autocomplete the word you’re typing. Hit CTRL-P again, VIM will find the previous match and use that instead. CTRL-N moves you in the opposite direction through the file. As soon as you type something other than one of these special characters you go right back to insert mode. This is the single feature of VIM I miss most when I have to use any other editor. Suddenly I have to make an effort to remember my temp-table / variable / procedure names again.

Quick Search


Position the cursor over a work, type *. VIM will jump to the next occurence of that word in the buffer, wrapping as necessary. If you use # instead of *, then the direction of the search is reversed.

Remembering your position.


Add this line to your .vimrc file –
:au BufReadPost * if line("'"") > 0 && line("'"") <= line("$") | exe "normal g'"" | endif

Now whenever you open a file it VIM, it will automtically jump to the position of your last edit.

Persistent Buffers


You probably know that Vi has named buffers and that when you’re yanking, deleting or putting lines of text you can specify which buffer to use. “e3yy for example will yank 3 lines into buffer “e”, you can then use “ep to place the contents of that buffer at the cursor position. One of the neat additions that VIM makes is that these buffers persist between editing sessions. This is great for having a few snippets of commonly used code always to hand ready to paste into whatever source file you’re editing.

@Functions


Another use of the named buffers is that you can use @ to execute the command stored in the specified buffer. This can be a standard VIM command or, particularly usefully, an EX command. I use this a lot for copying around the file(s) I’m currently editing. I have a file in my home directory on my Windows PC called shell.vim which contain a series of lines something like this –
:!rcp [cg]*.p appserver.asuser:/appserver/software/home/gr

I can open that file, pick the line I want and use “pyy to stick the line into the p buffer. Then I edit away at my source code, save it and use @p to stick it into a test directory on the appserver.

Multiple buffers.


Like any decent programming editor, VIM will allow you to open multiple files for editing and navigate quickly and easily between them. :bn will take you to the next open buffer, while :bp will take you in the opposite direction. :ls will give you a list of open buffers and their numbers, :b will switch to a specific buffer and :bd will close an open buffer. I have this line in my .vimrc which I find pretty handy –
map <f6> :bn<cr>

It allows me to repeatedly use F6 to cycle through the open buffers.

Plugin Scripts


www.vim.org has literally hundreds of add-on scripts available for VIM. Usually, it’s simply a matter of downloading them and dropping them into the plugin sub-directory of your VIM directory. I use Michael Geddes’s synabbrev.vim a lot. It allows you to setup abbreviations like the standard :ab command but with one important difference. It does not apply the abbreviations within comments. I have a file which looks something like this –
Synabbrev absolute ABSOLUTE
Synabbrev accelerator ACCELERATOR
Synabbrev accumulate ACCUMULATE
.

.

– which I use to acheive auto upper-casing of Progress keywords. Using synabbrev rather than ab makes my comments a lot more tidy. There are loads of other plugins available together with a pretty rich scripting language

Opening Include Files


Position the cursor over an include file, type gf. The include file should be opened in the editor. If you need to change the working / relative directory you can use :cd .

Block Indenting


You can use >> and << to indent and unindent blocks of code. 10>> will indent the current line and the next 10 lines, while >`a will indent everything down to mark a ( you can use m to set up to 26 named marks in a file, VIM persits these between sessions as well ). If you need to indent more than one level, just use the . key to repeat.

Edit this code ( my _vimrc file )


I’ve uploaded my _vimrc file and a couple of scripts. progressabs.vim is a script containing all of my abbreviations, progressuppercase.vim enabled auto upper casing of progress keywords and progressuppercaseoff.vim switched it off again. I’ve mapped these last two to and . To be honest, I uploaded them so wherever I am working I can easily get a hold of them, but help yourself. Let me know about any improvements you make and I’ll fold them back in.