Skip to content

Instantly share code, notes, and snippets.

@ovntatar
Created November 25, 2019 15:59
Show Gist options
  • Save ovntatar/b6928d4a56478de803bb09e1143b2e64 to your computer and use it in GitHub Desktop.
Save ovntatar/b6928d4a56478de803bb09e1143b2e64 to your computer and use it in GitHub Desktop.
vimrc Syntax Highlighting for Cisco
syntax enable
set background=dark
set nocompatible
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set ruler
set virtualedit=all
syn match ciscoIpAddr /\<\(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]\?\)\.\(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]\?\)\>/
hi def link ciscoIpAddrNumber
syn match ciscoIfName /\<\(Loopback\|Tunnel\|Dialer\)[0-9][0-9]*\>/
syn match ciscoIfName /Serial*/
syn match ciscoIfName +\<\(Ethernet\|FastEthernet\|ATM\)[0-9][0-9]*/[0-9][0-9]*\(/[0-9][0-9]*\)\?\(\.[0-9][0-9]*\)\?\>+
hi def link ciscoIfNameIdentifier
syn region ciscoNetwork start=+^.* is \(variably \)\?subnetted+ end=+^.* is \(variably \)\?subnetted+me=s-1 fold contains=ciscoIpAddr,ciscoIfName
syn match ipRoute /ip route/
syn match hostname /hostname/
hi def link hostname Identifier
set foldmethod=syntax
let b:current_syntax = "ciscoiproute"
"
" Vim syntax file
" Language: cisco access-list files
" Maintainer: Vladimir Kotal <[email protected]>
"
" Last Modification: 1-Dec-2004
"
" copy this file to ~/.vim/syntax/ directory (create dirs if they are not
" present) and add the following to your ~/.vimrc file:
"
" augroup filetype
" au! BufRead,BufNewFile *.acl set filetype=ciscoacl
" augroup END
"
" to create html file with highlighted syntax run
" runtime! syntax/2html.vim
"
"
syntax clear
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
" syntax case ignore
setlocal iskeyword+=/
setlocal iskeyword+=:
setlocal iskeyword+=.
setlocal iskeyword+=-
setlocal foldmethod=syntax
syn sync fromstart
" keywords
syntax keyword aclCmd permit
syntax keyword aclDeny deny
syntax keyword aclHost host
syntax keyword aclPort bgp chargen cmd daytime discard domain
syntax keyword aclPort echo exec finger ftp ftp-data gopher
syntax keyword aclPort hostname ident irc klogin kshell login
syntax keyword aclPort lpd nntp pim-auto-rp pop2 pop3 smtp sunrpc
syntax keyword aclPort syslog tacacs talk telnet time uucp whois
syntax keyword aclPort www biff bootpc bootps dnsix echo isakmp
syntax keyword aclPort mobile-ip nameserver netbios-dgm netbios-ns
syntax keyword aclPort netbios-ss ntp rip snmp snmptrap sunrpc
syntax keyword aclPort syslog talk tftp time who xdmcp
" protocols
"syntax keyword aclProto icmp ip tcp udp
syntax keyword aclSrcDst any
"syntax keyword aclSrcDst host
"syntax keyword aclLog log logging
" regexps
syntax match aclACL /^access-list\s+/
" TODO: differentaee network address/mask
"syntaon remark start="^access-list.*remark" end="$" contains=aclACL,aclDefine
syntax region remark start="remark " end="$"
"syntax region portspec start="eq" end="\s*[a-z0-9]*"
"syntax region portspec start="range" end="\s*[a-z0-9]*\s*[a-z0-9]*"
syntax match aclGenericNum /\<\d\+\>/
" Define the default hightlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_cisco_syn_inits")
if version < 508
let did_cisco_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
" special highlighting for deny keyword
hi Deny gui=bold guifg=LightRed ctermfg=White ctermbg=LightRed term=underline
HiLink aclDeny Deny
HiLink aclCmd Statement
HiLink ciscoip Type
HiLink remark String
HiLink ciscocomment Comment
HiLink portspec Type
HiLink aclDefine Identifier
HiLink aclGenericNum Constant
HiLink aclPort Constant
HiLink aclSrcDst Type
HiLink aclTodo Todo
delcommand HiLink
endif
let b:current_syntax = "cisco"
" vim:ts=4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment