Match IPv4 addresses and MAC addresses (colon- and dot-styles)
This plugin enables search matches of the following types:
- Traditional colon-style MAC addresses of the form xx:xx:xx:xx:xx:xx (ignoring case)
- Cisco dot-style MAC addresses of the form xxxx.xxxx.xxxx (ignoring case)
- IPv4 addresses of the form d.d.d.d, with each decimal octet restricted to 0-255
- IPv4 CIDR blocks of the form d.d.d.d/pfxlen, with pfxlen restricted to 0-32
- IPv4 private addresses and CIDR blocks (i.e., within blocks 10/8, 172.16/12, 192.168/16)
- IPv4 special and reserved addresses and CIDR blocks (all lumped together)
- IPv4 public addresses and CIDR blocks
In addition to matching the patterns noted above, the plugin enables the following.
- Conversion of colon-style MACs to dot-style MACs and vice-versa. (Note: when converting, dot-style MACs always are generated in lowercase.)
- Conversion of uppercase colon-style MACs to lowercase MACs and vice-versa.
The plugin defines the following command registrations and key mappings.
- Creates :xxx command registration aliases for the
AddressMatch()
function. (Set g:address_match_no_commands to disable.) - Creates
<leader>xxx
normal mode key mappings for match and convert operations. (Set g:address_match_no_mappings to disable.) - Creates text objects for all address types using the kana/vim-textobj-user plugin, establishing key mappings for search and selection. (Set g:address_match_no_textobj to disable.)
Unless g:address_match_no_commands is set, the following commands will be registered.
:MCM
MAC address colon-style match:MDM
MAC address dot-style match:MAM
MAC address any-style match
:MIP
IPv4 address match:MBL
IPv4 address block match (i.e., CIDR match n.n.n.n/p):MIS
IPv4 subnet match (same asMBL
above):MPR
IPv4 private address/block match (i.e., 10/8, 172.16/12, 192.168/16):MSP
IPv4 special address/block match (i.e., multicast, reserved):MPU
IPv4 public address/block match (neither private nor special)
Unless g:address_match_no_mappings is set, the following VIM normal-mode mappings will be defined.
<leader>mcm
MAC address colon-style match<leader>mdm
MAC address dot-style match<leader>mam
MAC address any-style match<leader>dtc
MAC address dot- to lower-case colon-style conversion, then match as withmcm
<leader>dtC
MAC address dot- to upper-case colon-style conversion, then match as withmcm
<leader>ctd
MAC address colon- to lower-case dot-style conversion, then match as withmdm
<leader>ctl
MAC address colon-style to lower-case conversion, then match as withmcm
<leader>ctu
MAC address colon-style to upper-case conversion, then match as withmcm
<leader>mip
IPv4 address match<leader>mbl
IPv4 address block match (i.e., CIDR match n.n.n.n/p)<leader>mis
IPv4 subnet match (same asmbl
above)<leader>maa
IPv4 any address/block match<leader>mpr
IPv4 private address/block match (i.e., 10/8, 172.16/12, 192.168/16)<leader>msp
IPv4 special address/block match (i.e., multicast, reserved)<leader>mpu
IPv4 public address/block match (neither private nor special)
Leveraging the
kana/vim-textobj-user
plugin, this plugin can treat MAC addresses and IPv4 addresses and address-blocks as textj objects.
This provides a set of motion-commands that can be used in conjunction with actions such as delete
and yank. It also establishes a set of navigation commands, leveraging the <localleader>
character.
If the vim-textobj-user plugin is not installed, or if g.address_match_no_textobj is set, text object functionality will be disabled.
If g.textobj_addressmatch_no_default_key_mappings set to True, the key mappings below will not
be established. (In other words :TextobjAddressmatchDefaultKeyMappings
will not be executed
automatically.)
In all of the following cases, the op
(yank, delete, etc.) will be executed upon the selected text
object. That object will be the one under the cursor or the next one in the buffer. The search will
not wrap to the beginning of the buffer. The cursor will be left positioned at the beginning of the
text object.
{op}acm
performop
on current/next colon-style MAC{op}adm
performop
on current/next dot-style MAC{op}aam
performop
on current/next any-style MAC{op}aip
performop
on current/next IPv4 address{op}abl
performop
on current/next IPv4 CIDR block{op}ais
performop
on current/next IPv4 subnet (same asabl
){op}aaa
performop
on current/next IPv4 address or block{op}apr
performop
on current/next IPv4 private address or block{op}apu
performop
on current/next IPv4 public address or block{op}asp
performop
on current/next IPv4 special address or block
In all of the following cases, the cursor will move to the beginning of the next matching text object. The search will not wrap to the beginning (or in the case of reverse search, end) of the buffer.
<localleader>cm
,<localleader>CM
forward, backward to colon-style MAC<localleader>dm
,<localleader>DM
forward, backward to dot-style MAC<localleader>am
,<localleader>AM
forward, backward to any-style MAC<localleader>ip
,<localleader>IP
forward, backward to IPv4 address<localleader>bl
,<localleader>BL
forward, backward to IPv4 CIDR block<localleader>is
,<localleader>IS
forward, backward to IPv4 subnet (same asbl
,BL
)<localleader>aa
,<localleader>aa
forward, backward to any IPv4 address/block<localleader>pr
,<localleader>pr
forward, backward to private IPv4 address/block<localleader>pr
,<localleader>pu
forward, backward to public IPv4 address/block<localleader>sp
,<localleader>sp
forward, backward to special IPv4 address/block
The regular expressions used to match MAC addresses and IPv4 addresses and blocks are available in the following global variables.
- g:address_match.dot_mac.pattern - dot-style MAC address
- g:address_match.colon_mac.pattern - colon-style MAC address
- g:address_match.any_mac.pattern - any-style MAC address
- g:address_match.ipv4.pattern - IPv4 address
- g:address_match.any_address.pattern - IPv4 address or address-block (CIDR)
- g:address_match.private.pattern - IPv4 private address (aka, RFC-1918)
- g:address_match.public.pattern - IPv4 public addresses (neither public nor special)
- g:address_match.special.pattern - IPv4 special addresses (multicast, reserved)
- g:address_match.cidr.pattern - IPv4 address block in CIDR notation, n.n.n.n/p