Wikia

Vim Tips Wiki

Match valid IP address

Talk0
1,613pages on
this wiki
Revision as of 21:14, January 10, 2011 by Trcollinson (Talk | contribs)

Tip 1073 Printable Monobook Previous Next

created December 9, 2005 · complexity basic · author Matous Jan Fialka · version 6.0


If a user is edit a file which contain IP addresses and would like to have them marked in a special color, adding the following code in their .vimrc file will highlight instances of IP addresses in the file being edited.

syn match ipaddr /\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)/
hi link ipaddr Identifier

This will highlight IP Addresses the same way identifiers are highlighted in source code files. This tip uses the following regular expression to find the address to be highlighted.

((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)

Other regular expressions can be used to find and highlight other patterns within text.

Comments

Around Wikia's network

Random Wiki