Vim Tips Wiki

Match valid IP address

1,613pages on
this wiki
Revision as of 07:17, January 22, 2011 by JohnBot (Talk | contribs)

Tip 1073 Printable Monobook Previous Next

created 2005 · complexity basic · author Matous Jan Fialka · version 6.0

When editing a file containing IP addresses, it may be helpful to highlight the addresses in a special color. Adding the following code to vimrc 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. The following regular expression is used to find each address to be highlighted.


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


Around Wikia's network

Random Wiki