Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #1436 - Wrap function calls in a print statement

Created: December 8, 2006 15:40 Complexity: advanced Author: Peter Jenkins Version: 5.7 Karma: 68/24 Imported from: Tip#1436

warning: i couldn't get this to work except by entering the commands, maybe there is a way to get the let statement to work but for me it has problems with the quotes. I couldn't figure out a way to properly escape them.


have you ever had a function in C: doSomething(a, b, c); and you want to see what it's printing out? this wraps that function so the output looks like this:


doSomething(a,b,c): 37


c for it looks like printf("doSomething(a,b,c): \"%s\"\n", doSomething(a,b,c));


kind of a pain to type often. i also try to make it so the cursor ends up over the s so that you can replace it with d, etc for printing things other than strings. again, this works if you type in the commands as they are depicted, but not with the let statement. if you want to do it by hand, do something like qt (to assign it to "t"). then type what's in between the quotes, starting with 0.



let @a = "0f(byt;iprintf("^[pa: "~@kb\"%s\"\n", ^[$i)^[?%^Ml^]"

Comments

An alternative would be to become a real programmer instead of a code-monkey and learn how to use a debugger; that's exactly the use-case of debuggers. But of course, the so called "programmers" or "developers" of today don't need the help of such arcane tools because they are agile and whatnot.

Anonymous , December 9, 2006 2:29


I know how to use a debugger, thank you. Sometimes a debugger is more overhead than I want to deal with.

Pete Jenkins , December 10, 2006 10:58


In fact, you can define

#define hcffl fprintf(stdout,"\n= [ %s : %s : %d ] =", \

__FILE__,__FUNCTION__,__LINE__ \ 
); fflush(stdout); 

then, add

hcffl;

every where you need, and

#define hcffl ;

to remove all these fprintf when make release version

huangchao--AT--hotmail.com , January 23, 2007 0:41


Advertisement