sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #1435: use recording to easily add function skeletons from prototypes

 tip karma   Rating -1/3, Viewed by 421 

created:   December 8, 2006 14:36      complexity:   intermediate
author:   Peter Jenkins      as of Vim:   5.7

Figuring this out showed me what vim is capable of.

:let @u = "<<<<<<<<<<dd?int main(^MkO^[pY/main(^M/{^M%o^M^[p^[kdd$s^M{^M^M^M}^[kki^I"

note, for ^M, ^I, ^[, you need to do ^v first. ^I may show up as a space. you might have to do ^v <tab>

this will take a function prototype wherever it is in your C code, make it flush left (if it's less than 5 or so tabs in), cut it and paste it one line above main, then copy it again to right under main, remove the semicolon, add paired braces, move in between them, tab over and put you in insert mode.

it could be  made nicer, but it gets the job done.

i guess i'm not using recording here, but that's how i generated the register. you can edit the recorded register as described here: vimtip#144





 rate this tip  Life Changing Helpful Unfulfilling 

<<as you type (or paste) in Makefile, autoconvert leading eight spaces to tab | wrap function calls in a print statement >>

Additional Notes

[email protected], December 8, 2006 14:39
whoops... just realized i could have done ^d$dd"2p instead of that messiness with the left shifts... oh well

Pete
lx(at)ua(dot)fm, December 9, 2006 14:55
The simplest way to remove all indentation on current line (if you mean that): ^d0
Pete Jenkins, December 10, 2006 10:59
Thank you. For some reason I never think of deleting backwards...
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