Syntax highlighting for hosts files


File under: sublime extension hosts .

Syntax highlighting for your hosts file

See this page on packagecontrol.io.

Syntax highlighting for your hosts file; /etc/hosts on Linux and macOS, C:\Windows\System32\Drivers\etc\hosts (?) on Windows.

This is a complete rewrite of an older Hosts package that provided more or less the same thing, except of course for some improvements:

  • It only highlights IP addresses that are actually viable. For example: it won’t match the impossible movie IP-address 189.23.290.13. (Bytes cannot have values higher than 255…) This makes it easier to spot errors.
  • It makes IP addresses in three private ranges stand out by giving them a different colour. It supports all three private ranges: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.
  • Loopback addresses (127.0.0.0/8 and ::1) get a distinguishable colour too. (Thanks to Michael B. Lyons).
  • It indexes the hosts so you can use Goto Symbol to quickly go there. (Made by Michael Blyons)
  • IPv6

Credit where credit’s due:

David M. Syzdek wrote the regular expressions for matching IP-addresses that I adapted for this plugin.

The mysterious Michael B. Lyons provided several pull requests with a range of features and fixes. In fact, he added so much that you can consider it to be a complete rewrite of the code we started with.