vim tricks for constructing header files

L

luser- -droog

I've just cobbled together a few tricks that save a bunch of
keystrokes when generating the .h file from a freshly written
..c file.

A freshly written .c file:
1
2 #include "m.h"
3 #include "ob.h"
4
5 object consarr(mfile *mem, unsigned sz) {
6 unsigned ent = mtalloc(mem, sz * sizeof(object));
7 return (object){ .tag = arraytype, .sz = sz, .ent = ent, .off
= 0};
8 }
9
10 void arrput(mfile *mem, object a, integer i, object o) {
11 put(mem, a.comp_.ent, a.comp_.off + i, sizeof(object), &o);
12 }
13
14 object arrget(mfile *mem, object a, integer i) {
15 object o;
16 get(mem, a.comp_.ent, a.comp_.off + i, sizeof(object), &o);
17 return o;
18 }
19
"ar.c" 19L, 472C written

then switch to new file
:e ar.h
load previous file
:r #
trim headers
d}
replace function body with semicolon
j$c%;ESC
reposition, repeat change
jj$.
again
jj.
et voila:

1
2 object consarr(mfile *mem, unsigned sz);
3
4 void arrput(mfile *mem, object a, integer i, object o);
5
6 object arrget(mfile *mem, object a, integer i);
7
"ar.h" 7L, 149C written
 
R

Rui Maciel

luser- -droog said:
then switch to new file
:e ar.h
load previous file
:r #
trim headers
d}
replace function body with semicolon
j$c%;ESC
reposition, repeat change
jj$.
again
jj.
et voila:

You can go a step further and record a macro with that list of commands or
map a specific keyboard shortcut to that script.


Rui Maciel
 
O

Old Wolf

I've just cobbled together a few tricks that save a bunch of
keystrokes when generating the .h file from a freshly written
.c file.

Have to say that I always write the .h file first.

Define and document the interface between units first,
and implement it later -- good design IMHO.

Then all you have to do is copy the .h file to the .c file
and change semicolons to curly braces.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top