Wikia

Vim Tips Wiki

Changes: Match valid IP address

Edit

Back to page

(Reviewed, cleaned up.)
(formatting and some rewording)
Line 3: Line 3:
 
|previous=1072
 
|previous=1072
 
|next=1074
 
|next=1074
|created=December 9, 2005
+
|created=2005
 
|complexity=basic
 
|complexity=basic
 
|author=Matous Jan Fialka
 
|author=Matous Jan Fialka
Line 11: Line 11:
 
|category2=Usage
 
|category2=Usage
 
}}
 
}}
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.
+
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.
 
<pre>
 
<pre>
 
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]\?\)/
 
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]\?\)/
Line 17: Line 17:
 
</pre>
 
</pre>
   
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.
+
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.
 
<pre>
 
<pre>
 
((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]?)
 
((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]?)

Revision as of 07:17, January 22, 2011

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