Wednesday, December 4, 2013

Re: How would a vim guru type this c++ snippet?

On 14:02 Wed 04 Dec , Chris Stankevitz wrote:
> Thank you for your help! I will take a look at lh-vim.
>
> Without internet access on a new install of vim, how would a vim guru
> would convert this:
>
> float mTemperature;
>
> unsigned char mType;
>
> double mDistanceFromCenter;
>
> long long int mId;
>
> std::string mName;
>
> Into this:
> mTemperature(Other.mTemperature),
> mType(Other.mType),
> mDistanceFromCenter(Other.mDistanceFromCenter),
> mId(Other.mId),
> mName(Other.mName),
>
> I suspect, the guru would do one of:
>
> 1. copy the parameters into a blank text document. Strip the variable
> types, semicolon, and whitespace. Past the results into a spreadsheet
> program. Use a formula '=A1 & "(Other." & A1 & "),"'. Repeat
> formula, copy, paste into vim.
>
> 2. A gnarly regular expression
In most cases one has to type a bit more, usually macros are more
efficient.
:%s/\v\w.*\s+(\w+);/\1(Other.\1),
(And you still need to delete the lines)
> 3. Some clever 'q' gymnastics
Indeed, it seems a macro might be a good idea:
qq$Bd^yeea(Other. ") lr,
ddq

And then play the macro with 4@q .

Cheers,
Marcin

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: