What I would really like is to just do the ^N on the initial "_some_root", see that the popup menu shows the correct four
values, and press some key combo to insert them all on
consecutive lines like above. I'm not even fussy if it inserts
the "case" and the ":", I can very easily do them myself with
a couple of key presses.

I'm not sure how to go about pulling in the list of
auto-completion possibilities (such as one gets with ^N and ^P as
you describe). I *usually* have all such items I want in a switch
statement defined in an enum somewhere, so I just copy the
contents of that enum and then perform a :s across them, such as

typedef enum {
TAPIOCA,
SPATULA,
CATALOG,
MYOPIC
} RandomStuff;

I then copy those contents to my switch() statement:

switch (foo)
{
TAPIOCA,
SPATULA,
CATALOG,
MYOPIC
}

and then, selecting the lines with "vi{", I can run

:'<,'>s/,/
:'<,'>s/.*/   case &: break;

or if you prefer in a mappable one-liner

:'<,'>s/^\s*\(.\{-}\),\=$/case \1: break;

You'd then have to adjust indentation accordingly, but if you've
got scads of items in your enum, it's an easy way to go about it.

Alternatively, if they're not in an enum, and you have to gather
them from around the document, you can do something like

        ma

on a blank line where you intend your results to go, and then do

        :g/_some_root/t'a

which will bring all sorts of lines containing this item into
those braces.  You can then tidy them up a bit with something like

        vi{
        :'<,'>s/.*\(_some_root\w*\).*/case \1: break;
        :'<,'>!sort -u

(assuming you have an external "sort" capible of eliminating
duplicate lines with the "-u"nique parameter, such as GNU sort on
most *nix systems...as your email address is at Microsoft, you
might not have GNU tools quite so readily available ;)

I'm not sure if there are easier ways or more automated ways to
find a unique list of autocompletion-matches...especially if they
span open buffers (as ^N and ^P do)

Just a few ideas though as you cavort towards a solution,

-tim




Reply via email to