sponsor Vim development Vim logo Vim Book Ad

advanced Tip #1436: wrap function calls in a print statement

 tip karma   Rating -3/5, Viewed by 441 

created:   December 8, 2006 15:40      complexity:   advanced
author:   Peter Jenkins      as of Vim:   5.7

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^]"

 rate this tip  Life Changing Helpful Unfulfilling 

<<use recording to easily add function skeletons from prototypes | Using VIM with the Dvorak Keyboard Layout >>

Additional Notes

Anonymous, December 9, 2006 2:29
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.
[email protected], December 9, 2006 11:13
salam
Pete Jenkins, December 10, 2006 10:58
I know how to use a debugger, thank you. Sometimes a debugger is more overhead than I want to deal with.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
    stats
Sponsored by Web Concept Group Inc. SourceForge.net Logo