vim syntax highlighting

If you make changes/bug fixes/add features to this file please either edit this version or paste yours at the end.

To use syntax highlighting paste syntax definition file that is shown below into a text file called asterisk.vim and save it in your home dir.

However, many vim installations already come with asterisk.vim and asteriskvm.vim (for example Debian does), so that all you really need to do is turn syntax highlighting on. You can do that, for example, in .vimrc in your home directory with the line "syntax on", or you can do so on a case-by-case approach while inside the vim editor with ":syntax on".

First open extensions.conf in vim:
vim /usr/src/asterisk/configs/extensions.conf.sample

Then inside vim type the following:
:syntax on
:source path/to/asterisk.vim



Assuming the file below is saved instead in ~/.vim/syntax/asterisk.vim, you can automate the commands above by adding the following line to the very bottom of each of your /etc/asterisk/*.conf files:
vim
set ts=8 sw=2 filetype=asterisk:
This works on my latest FC2 machine without any other VIM adjustments.

or

Here's another approach to make Vim autoload the syntax file below.

First, create the file in:

/usr/share/vim/vim63/syntax/asterisk.vim
OR
/usr/share/vim/syntax/asterisk.vim (for Mandriva)

where all the other syntax files are. (This will cause this to affect all users, of course).

Next, make this addition to the

/usr/share/vim/vim63/filetype.vim

file:

" Asterisk config file
au BufNewFile,BufRead *asterisk*/*voicemail.conf* setf asterisk_voicemail
au BufNewFile,BufRead *asterisk/*.conf* setf asterisk
au BufNewFile,BufRead *asterisk/*.ael* setf asterisk

This will basically cause any .conf file in the /etc/asterisk directory to use the below "asterisk" type highlighting. You could make it more specific and this will naturally just pickup the .conf files in certain directories, but I found it more convenient than anything else.





" Vim syntax file
" Language:	Asterisk config file
" Maintainer:	brc007 
" Updated for 1.6.2 by Tilghman Lesher (Corydon76)
" Last Change:	2008 Oct 10 
" version 0.5
"
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

syn sync clear
syn sync fromstart

syn keyword     asteriskTodo            TODO contained
syn match       asteriskComment         ";.*" contains=asteriskTodo
syn match       asteriskContext         "\[.\{-}\]"
syn match       asteriskExten           "^\s*exten\s*=>\?\s*[^,]\+" contains=asteriskPattern
syn match       asteriskExten           "^\s*same\s*=>\?\s*[^,]\+" contains=asteriskPriority
syn match       asteriskExten           "^\s*\(register\|channel\|ignorepat\|include\|\(no\)\?load\)\s*=>\?"
syn match       asteriskPattern         "_\(\[[[:alnum:]#*\-]\+\]\|[[:alnum:]#*\-]\)*\.\?" contained
syn match       asteriskPattern         "[^A-Za-z0-9,]\zs[[:alnum:]#*\-]\+\ze" contained
syn match       asteriskApp             ",\zs[a-zA-Z]\+\ze$"
syn match       asteriskApp             ",\zs[a-zA-Z]\+\ze("
" Digits plus oldlabel (newlabel)
syn match       asteriskPriority        "\zs[[:digit:]]\+\(+[[:alpha:]][[:alnum:]_]*\)\?\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
" oldlabel plus digits (newlabel)
syn match       asteriskPriority        "\zs[[:alpha:]][[:alnum:]_]*+[[:digit:]]\+\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
" s or n plus digits (newlabel)
syn match       asteriskPriority        "\zs[sn]\(+[[:digit:]]\+\)\?\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
syn match       asteriskLabel           "(\zs[[:alpha:]][[:alnum:]]*\ze)" contained
syn match       asteriskError           "^\s*#\s*[[:alnum:]]*"
syn match       asteriskInclude         "^\s*#\s*\(include\|exec\)\s.*"
syn match       asteriskVar             "\${_\{0,2}[[:alpha:]][[:alnum:]_]*\(:-\?[[:digit:]]\+\(:-\?[[:digit:]]\+\)\?\)\?}"
syn match       asteriskVar             "_\{0,2}[[:alpha:]][[:alnum:]_]*\ze="
syn match       asteriskVarLen          "\${_\{0,2}[[:alpha:]][[:alnum:]_]*(.*)\(:-\?[[:digit:]]\+\(:-\?[[:digit:]]\+\)\?\)\?}" contains=asteriskVar,asteriskVarLen,asteriskExp
syn match       asteriskVarLen          "(\zs[[:alpha:]][[:alnum:]_]*(.*)\ze=" contains=asteriskVar,asteriskVarLen,asteriskExp
syn match       asteriskExp             "\$\[.*\]" contains=asteriskVar,asteriskVarLen,asteriskExp
syn match       asteriskCodecsPermit    "^\s*\(allow\|disallow\)\s*=\s*.*$" contains=asteriskCodecs
syn match       asteriskCodecs          "\(g723\|gsm\|ulaw\|alaw\|g726\|adpcm\|slin\|lpc10\|g729\|speex\|ilbc\|all\s*$\)"
syn match       asteriskError           "^\(type\|auth\|permit\|deny\|bindaddr\|host\)\s*=.*$"
syn match       asteriskType            "^\zstype=\ze\<\(peer\|user\|friend\)\>$" contains=asteriskTypeType
syn match       asteriskTypeType        "\<\(peer\|user\|friend\)\>" contained
syn match       asteriskAuth            "^\zsauth\s*=\ze\s*\<\(md5\|rsa\|plaintext\)\>$" contains=asteriskAuthType
syn match       asteriskAuthType        "\<\(md5\|rsa\|plaintext\)\>"
syn match       asteriskAuth            "^\zs\(secret\|inkeys\|outkey\)\s*=\ze.*$"
syn match       asteriskAuth            "^\(permit\|deny\)\s*=\s*\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\s*$" contains=asteriskIPRange
syn match       asteriskIPRange         "\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}" contained
syn match       asteriskIP              "\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}" contained
syn match       asteriskHostname        "[[:alnum:]][[:alnum:]\-\.]*\.[[:alpha:]]{2,10}" contained
syn match       asteriskPort            "\d\{1,5}" contained
syn match       asteriskSetting         "^bindaddr\s*=\s*\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}$" contains=asteriskIP
syn match       asteriskSetting         "^port\s*=\s*\d\{1,5}\s*$" contains=asteriskPort
syn match       asteriskSetting         "^host\s*=\s*\(dynamic\|\(\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\)\|\([[:alnum:]][[:alnum:]\-\.]*\.[[:alpha:]]{2,10}\)\)" contains=asteriskIP,asteriskHostname

" Define the default highlighting.
" 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_conf_syntax_inits")
  if version < 508
    let did_conf_syntax_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink        asteriskComment		Comment
  HiLink        asteriskExten		String
  HiLink        asteriskContext         Preproc
  HiLink        asteriskPattern         Type
  HiLink        asteriskApp             Statement
  HiLink        asteriskInclude         Preproc
  HiLink        asteriskIncludeBad	Error
  HiLink        asteriskPriority        Preproc
  HiLink        asteriskLabel           Type
  HiLink        asteriskVar             String
  HiLink        asteriskVarLen          Function
  HiLink        asteriskExp             Type
  HiLink        asteriskCodecsPermit    Preproc
  HiLink        asteriskCodecs          String
  HiLink        asteriskType            Statement
  HiLink        asteriskTypeType        Type
  HiLink        asteriskAuth            String
  HiLink        asteriskAuthType        Type
  HiLink        asteriskIPRange         Identifier
  HiLink        asteriskIP              Identifier
  HiLink        asteriskPort            Identifier
  HiLink        asteriskHostname        Identifier
  HiLink        asteriskSetting         Statement
  HiLink        asteriskError           Error
 delcommand HiLink
endif
let b:current_syntax = "asterisk" 
" vim: ts=8 sw=2



We also have a separate configuration file for voicemail configuration now:


" Vim syntax file
" Language:	Asterisk voicemail config file
" Maintainer: Tilghman Lesher (Corydon76)
" Last Change:	2006 Mar 20 
" version 0.2
"
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

syn sync clear
syn sync fromstart


syn keyword     asteriskTodo    TODO contained
syn match       asteriskComment         ";.*" contains=asteriskTodo
syn match       asteriskContext         "\[.\{-}\]"

" ZoneMessages
syn match       asteriskZone            "^[[:alnum:]]\+\s*=>\?\s*[[:alnum:]/_]\+|.*$" contains=zoneName,zoneDef
syn match       zoneName                "=\zs[[:alnum:]/_]\+\ze" contained
syn match       zoneDef                 "|\zs.*\ze$" contained

syn match       asteriskSetting         "\<\(format\|serveremail\|minmessage\|maxmessage\|maxgreet\|skipms\|maxsilence\|silencethreshold\|maxlogins\)="
syn match       asteriskSetting         "\<\(externnotify\|externpass\|directoryintro\|charset\|adsi\(fdn\|sec\|ver\)\|\(pager\)\?fromstring\|email\(subject\|body\|cmd\)\|tz\|cidinternalcontexts\|saydurationm\|dialout\|callback\)="
syn match       asteriskSettingBool     "\<\(attach\|pbxskip\|usedirectory\|saycid\|sayduration\|sendvoicemail\|review\|operator\|envelope\|delete\|nextaftercmd\|forcename\|forcegreeting\)=\(yes\|no\|1\|0\|true\|false\|t\|f\)"

" Individual mailbox definitions
syn match       asteriskMailbox         "^[[:digit:]]\+\s*=>\?\s*[[:digit:]]\+\(,[^,]*\(,[^,]*\(,[^,]*\(,[^,]*\)\?\)\?\)\?\)\?" contains=mailboxEmail,asteriskSetting,asteriskSettingBool,comma
syn match       mailboxEmail            ",\zs[^@=,]*@[[:alnum:]\-\.]\+\.[[:alpha:]]\{2,10}\ze" contains=comma
syn match       comma                   "[,|]" contained

" Define the default highlighting.
" 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_conf_syntax_inits")
  if version < 508
    let did_conf_syntax_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink        asteriskComment Comment
  HiLink        asteriskContext         Identifier
  HiLink        asteriskZone            Type
  HiLink        zoneName                String
  HiLink        zoneDef                 String
  HiLink        asteriskSetting         Type
  HiLink        asteriskSettingBool     Type

  HiLink        asteriskMailbox         Statement
  HiLink        mailboxEmail            String
 delcommand HiLink
endif

let b:current_syntax = "asterisk_voicemail"

" vim: ts=8 sw=2


Both above documents are BSD licensed. if you make any changes/improvements to these syntax files, please edit this page and add them! :-)

See Also

If you make changes/bug fixes/add features to this file please either edit this version or paste yours at the end.

To use syntax highlighting paste syntax definition file that is shown below into a text file called asterisk.vim and save it in your home dir.

However, many vim installations already come with asterisk.vim and asteriskvm.vim (for example Debian does), so that all you really need to do is turn syntax highlighting on. You can do that, for example, in .vimrc in your home directory with the line "syntax on", or you can do so on a case-by-case approach while inside the vim editor with ":syntax on".

First open extensions.conf in vim:
vim /usr/src/asterisk/configs/extensions.conf.sample

Then inside vim type the following:
:syntax on
:source path/to/asterisk.vim



Assuming the file below is saved instead in ~/.vim/syntax/asterisk.vim, you can automate the commands above by adding the following line to the very bottom of each of your /etc/asterisk/*.conf files:
vim
set ts=8 sw=2 filetype=asterisk:
This works on my latest FC2 machine without any other VIM adjustments.

or

Here's another approach to make Vim autoload the syntax file below.

First, create the file in:

/usr/share/vim/vim63/syntax/asterisk.vim
OR
/usr/share/vim/syntax/asterisk.vim (for Mandriva)

where all the other syntax files are. (This will cause this to affect all users, of course).

Next, make this addition to the

/usr/share/vim/vim63/filetype.vim

file:

" Asterisk config file
au BufNewFile,BufRead *asterisk*/*voicemail.conf* setf asterisk_voicemail
au BufNewFile,BufRead *asterisk/*.conf* setf asterisk
au BufNewFile,BufRead *asterisk/*.ael* setf asterisk

This will basically cause any .conf file in the /etc/asterisk directory to use the below "asterisk" type highlighting. You could make it more specific and this will naturally just pickup the .conf files in certain directories, but I found it more convenient than anything else.





" Vim syntax file
" Language:	Asterisk config file
" Maintainer:	brc007 
" Updated for 1.6.2 by Tilghman Lesher (Corydon76)
" Last Change:	2008 Oct 10 
" version 0.5
"
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

syn sync clear
syn sync fromstart

syn keyword     asteriskTodo            TODO contained
syn match       asteriskComment         ";.*" contains=asteriskTodo
syn match       asteriskContext         "\[.\{-}\]"
syn match       asteriskExten           "^\s*exten\s*=>\?\s*[^,]\+" contains=asteriskPattern
syn match       asteriskExten           "^\s*same\s*=>\?\s*[^,]\+" contains=asteriskPriority
syn match       asteriskExten           "^\s*\(register\|channel\|ignorepat\|include\|\(no\)\?load\)\s*=>\?"
syn match       asteriskPattern         "_\(\[[[:alnum:]#*\-]\+\]\|[[:alnum:]#*\-]\)*\.\?" contained
syn match       asteriskPattern         "[^A-Za-z0-9,]\zs[[:alnum:]#*\-]\+\ze" contained
syn match       asteriskApp             ",\zs[a-zA-Z]\+\ze$"
syn match       asteriskApp             ",\zs[a-zA-Z]\+\ze("
" Digits plus oldlabel (newlabel)
syn match       asteriskPriority        "\zs[[:digit:]]\+\(+[[:alpha:]][[:alnum:]_]*\)\?\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
" oldlabel plus digits (newlabel)
syn match       asteriskPriority        "\zs[[:alpha:]][[:alnum:]_]*+[[:digit:]]\+\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
" s or n plus digits (newlabel)
syn match       asteriskPriority        "\zs[sn]\(+[[:digit:]]\+\)\?\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
syn match       asteriskLabel           "(\zs[[:alpha:]][[:alnum:]]*\ze)" contained
syn match       asteriskError           "^\s*#\s*[[:alnum:]]*"
syn match       asteriskInclude         "^\s*#\s*\(include\|exec\)\s.*"
syn match       asteriskVar             "\${_\{0,2}[[:alpha:]][[:alnum:]_]*\(:-\?[[:digit:]]\+\(:-\?[[:digit:]]\+\)\?\)\?}"
syn match       asteriskVar             "_\{0,2}[[:alpha:]][[:alnum:]_]*\ze="
syn match       asteriskVarLen          "\${_\{0,2}[[:alpha:]][[:alnum:]_]*(.*)\(:-\?[[:digit:]]\+\(:-\?[[:digit:]]\+\)\?\)\?}" contains=asteriskVar,asteriskVarLen,asteriskExp
syn match       asteriskVarLen          "(\zs[[:alpha:]][[:alnum:]_]*(.*)\ze=" contains=asteriskVar,asteriskVarLen,asteriskExp
syn match       asteriskExp             "\$\[.*\]" contains=asteriskVar,asteriskVarLen,asteriskExp
syn match       asteriskCodecsPermit    "^\s*\(allow\|disallow\)\s*=\s*.*$" contains=asteriskCodecs
syn match       asteriskCodecs          "\(g723\|gsm\|ulaw\|alaw\|g726\|adpcm\|slin\|lpc10\|g729\|speex\|ilbc\|all\s*$\)"
syn match       asteriskError           "^\(type\|auth\|permit\|deny\|bindaddr\|host\)\s*=.*$"
syn match       asteriskType            "^\zstype=\ze\<\(peer\|user\|friend\)\>$" contains=asteriskTypeType
syn match       asteriskTypeType        "\<\(peer\|user\|friend\)\>" contained
syn match       asteriskAuth            "^\zsauth\s*=\ze\s*\<\(md5\|rsa\|plaintext\)\>$" contains=asteriskAuthType
syn match       asteriskAuthType        "\<\(md5\|rsa\|plaintext\)\>"
syn match       asteriskAuth            "^\zs\(secret\|inkeys\|outkey\)\s*=\ze.*$"
syn match       asteriskAuth            "^\(permit\|deny\)\s*=\s*\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\s*$" contains=asteriskIPRange
syn match       asteriskIPRange         "\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}" contained
syn match       asteriskIP              "\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}" contained
syn match       asteriskHostname        "[[:alnum:]][[:alnum:]\-\.]*\.[[:alpha:]]{2,10}" contained
syn match       asteriskPort            "\d\{1,5}" contained
syn match       asteriskSetting         "^bindaddr\s*=\s*\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}$" contains=asteriskIP
syn match       asteriskSetting         "^port\s*=\s*\d\{1,5}\s*$" contains=asteriskPort
syn match       asteriskSetting         "^host\s*=\s*\(dynamic\|\(\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\)\|\([[:alnum:]][[:alnum:]\-\.]*\.[[:alpha:]]{2,10}\)\)" contains=asteriskIP,asteriskHostname

" Define the default highlighting.
" 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_conf_syntax_inits")
  if version < 508
    let did_conf_syntax_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink        asteriskComment		Comment
  HiLink        asteriskExten		String
  HiLink        asteriskContext         Preproc
  HiLink        asteriskPattern         Type
  HiLink        asteriskApp             Statement
  HiLink        asteriskInclude         Preproc
  HiLink        asteriskIncludeBad	Error
  HiLink        asteriskPriority        Preproc
  HiLink        asteriskLabel           Type
  HiLink        asteriskVar             String
  HiLink        asteriskVarLen          Function
  HiLink        asteriskExp             Type
  HiLink        asteriskCodecsPermit    Preproc
  HiLink        asteriskCodecs          String
  HiLink        asteriskType            Statement
  HiLink        asteriskTypeType        Type
  HiLink        asteriskAuth            String
  HiLink        asteriskAuthType        Type
  HiLink        asteriskIPRange         Identifier
  HiLink        asteriskIP              Identifier
  HiLink        asteriskPort            Identifier
  HiLink        asteriskHostname        Identifier
  HiLink        asteriskSetting         Statement
  HiLink        asteriskError           Error
 delcommand HiLink
endif
let b:current_syntax = "asterisk" 
" vim: ts=8 sw=2



We also have a separate configuration file for voicemail configuration now:


" Vim syntax file
" Language:	Asterisk voicemail config file
" Maintainer: Tilghman Lesher (Corydon76)
" Last Change:	2006 Mar 20 
" version 0.2
"
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

syn sync clear
syn sync fromstart


syn keyword     asteriskTodo    TODO contained
syn match       asteriskComment         ";.*" contains=asteriskTodo
syn match       asteriskContext         "\[.\{-}\]"

" ZoneMessages
syn match       asteriskZone            "^[[:alnum:]]\+\s*=>\?\s*[[:alnum:]/_]\+|.*$" contains=zoneName,zoneDef
syn match       zoneName                "=\zs[[:alnum:]/_]\+\ze" contained
syn match       zoneDef                 "|\zs.*\ze$" contained

syn match       asteriskSetting         "\<\(format\|serveremail\|minmessage\|maxmessage\|maxgreet\|skipms\|maxsilence\|silencethreshold\|maxlogins\)="
syn match       asteriskSetting         "\<\(externnotify\|externpass\|directoryintro\|charset\|adsi\(fdn\|sec\|ver\)\|\(pager\)\?fromstring\|email\(subject\|body\|cmd\)\|tz\|cidinternalcontexts\|saydurationm\|dialout\|callback\)="
syn match       asteriskSettingBool     "\<\(attach\|pbxskip\|usedirectory\|saycid\|sayduration\|sendvoicemail\|review\|operator\|envelope\|delete\|nextaftercmd\|forcename\|forcegreeting\)=\(yes\|no\|1\|0\|true\|false\|t\|f\)"

" Individual mailbox definitions
syn match       asteriskMailbox         "^[[:digit:]]\+\s*=>\?\s*[[:digit:]]\+\(,[^,]*\(,[^,]*\(,[^,]*\(,[^,]*\)\?\)\?\)\?\)\?" contains=mailboxEmail,asteriskSetting,asteriskSettingBool,comma
syn match       mailboxEmail            ",\zs[^@=,]*@[[:alnum:]\-\.]\+\.[[:alpha:]]\{2,10}\ze" contains=comma
syn match       comma                   "[,|]" contained

" Define the default highlighting.
" 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_conf_syntax_inits")
  if version < 508
    let did_conf_syntax_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink        asteriskComment Comment
  HiLink        asteriskContext         Identifier
  HiLink        asteriskZone            Type
  HiLink        zoneName                String
  HiLink        zoneDef                 String
  HiLink        asteriskSetting         Type
  HiLink        asteriskSettingBool     Type

  HiLink        asteriskMailbox         Statement
  HiLink        mailboxEmail            String
 delcommand HiLink
endif

let b:current_syntax = "asterisk_voicemail"

" vim: ts=8 sw=2


Both above documents are BSD licensed. if you make any changes/improvements to these syntax files, please edit this page and add them! :-)

See Also

Created by: brc007, Last modification: Thu 04 of Aug, 2011 (14:13 UTC) by msaalfrank
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+