Friday, January 8, 2010

Is there a way to predefine search patterns?

What's a good way to predefine commonly used but complex search
patterns so they can be quickly invoked? I'm sure this is a common
requirement but I can't find anything searching around.

Specific example: I often want to search for IP addresses in files, so
I'll search like this:

/\([0-9]\{1,3}\.\)\{3}[0-9]\{1,3}

The best solution I've come up with is

:nmap /ip /\([0-9]\{1,3}\.\)\{3}[0-9]\{1,3}

but if I'm too slow to type it gives up and works as the literal
command /ip. (Actually that might be quite useful in some
circumstances.) I don't want to change the general timeout time just
for this case. "ip" is trivial to type but I'm thinking of the more
general case of defining long pattern names.

I was thinking I'd be able to configure patterns somewhere so I could
do something like the below command (following character class
syntax), but I can't find a way to do it.

/[:ip:]

regards,
Geoff

No comments: