Simple C Template Editor via Vi
toc at dadla.UUCP
toc at dadla.UUCP
Thu Dec 20 10:03:49 AEST 1984
-------
[No matter where you go...
Presented for your approval...
Under the "cut here" line below will be found a shell script I
call `cvi' (to be linked with another called `cview'). This
script sets up a set of vi macros which turn that lovely and
talented editor into a very convenient Template Editor for C.
I've been using it for several weeks now to edit my programs and
have uncovered no major bugs or hassles. I submit it to the
gentle :-) folk of the net in hopes that others may find it as
useful.
Basically it allows one to enter C language constructs with a
minimum of keystrokes and syntactical errors. Three keystrokes
are all that needed to enter the following construct:
main(argc, argv, environ)
int argc;
char *argv[], *environ[];
{
$
}
After the construct is built the user is left in insert mode at
the position indicated by the dollar ('$', note: the dollar
only appears in this example, not in real life. Appending the
string "$^[s" to each macro should make it appear in real life).
Typing away enters more text at that position. The three keystrokes
used for the above were ma' (assuming the editor was already in
insert mode).
The only hassle with using cvi is that timeout must be set. Timeout
tells vi to watch for one second (roughly) before entering text
into the buffer. This gives you a limited time to enter the
entire macro and seems to have the effect of slowing down regular
text entry (vi waits to see if a macro name is coming). This
does allow the macros to be entered as regular text, however,
just type them slowly. It also makes it sometimes necessary to enter
a macro more than once. If this becomes a problem then just pull
the `set timeout' out of the shell script.
I won't detail the keystrokes here, reading thru the below script
should provide enough information in that regard. The macros are
set up to enter code in my personal coding style. From the never
ending discussions on style I've noted that mine is preferred by
the minority. Changing this to fit your style should be easy :-)
Just remember that the macros are simply strings of characters
written to vi and that ^x means control-x (or whatever other
character may be in the place of x). I personally feel that the
macros are perfect just as they are, but the spice of life and
all that.
Quick instructional hints. The macros work only when the editor
is in insert mode. Undo will not undo the entry of the entire
construct as it took several do's to get it there.
As noted (in passing) above the below script needs to contain control
characters in order to work properly. The script below contains
none in order to get it across the net properly (and I thought
I'd never find a use for cat -v!!!). So, before you attempt to
use cvi, replace all of the ^M's, ^['s, & ^D's below with the real
control character.
This has really gone on too long already. I'll gladly take *help-
ful*, *constructive*, or *Help Me!!!* mail, let it build up a bit,
and disperse responses to the appropriate place(s). Please let's
not have any discussions on coding styles...
...there you are]
to'c
~~~~~~~~cut here~~~~~~~~cut here~~~~~~~~cut here~~~~~~~~cut here~~~~~~~~
EXINIT="set autoindent|set timeout|set noremap\
|map! #/ /**/^M/* ^M/**/^[kA\
|map! #in #include <>^[i\
|map! #de #define /* */^[0f a\
|map! #un #undef\
|map! #id #ifdef \
|map! #if #if ()^[i\
|map! #el #else^M\
|map! #en #endif^M\
|map! au' auto ;^[i\
|map! br' break;\
|map! ca' ^M^Dcase : /**/^M break;^[k0f:i\
|map! ch' char ;^[i\
|map! co' continue;\
|map! de' ^M^Ddefault: /**/^M break;^[O\
|map! do' double ;^[i\
|map! dw' do^M{^M}^Mwhile();^[kO \
|map! ei' else if ()^M{^M}^[kk0f(a\
|map! el' else^M{^M}^[O \
|map! en' enum {};^[hi\
|map! ex' extern ;^[i\
|map! fl' float ;^[i\
|map! fo' for (; ; )^M{^M}^[kk0f(a\
|map! go' goto ;^[i\
|map! if' if ()^M{^M}^[kk0f(a\
|map! in' int ;^[i\
|map! lo' long ;^[i\
|map! ma' ^Mmain(argc, argv, environ)^Mint argc;^Mchar *argv[], *environ[];^M{^M}^[O \
|map! re' return ();^[hi\
|map! rg' register ;^[i\
|map! sc' static ;^[i\
|map! sh' short ;^[i\
|map! si' sizeof ()^[i\
|map! st' struct ^M{^M};^[kkA\
|map! sw' switch ()^M{^M case : /**/^M break;^M^D^D}^[kkkk0f(a\
|map! ty' typedef ;^[i\
|map! un' union^M{^M};^[O \
|map! us' unsigned ;^[i\
|map! wh' while ()^M{^M}^[kk0f(a\
"
case `basename $0` in
cvi) NAME=vi
;;
cview) NAME=view
;;
esac
export EXINIT
exec /usr/ucb/$NAME $*
More information about the Comp.sources.unix
mailing list