Wikia

Vim Tips Wiki

Match valid IP address

Talk0
1,610pages 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.

((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