Vim Tips Wiki

Match valid IP address

Revision as of 21:14, January 10, 2011 by Trcollinson (Talk | contribs)

1,619pages on
this wiki
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.


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


Around Wikia's network

Random Wiki