Skip to content

Instantly share code, notes, and snippets.

@The-King-of-Toasters
Last active August 10, 2019 04:45
Show Gist options
  • Save The-King-of-Toasters/4f4688498529b37476880a73c6401533 to your computer and use it in GitHub Desktop.
Save The-King-of-Toasters/4f4688498529b37476880a73c6401533 to your computer and use it in GitHub Desktop.
Vim Syntax Highlighting for mbsyncrc
" Vim syntax file
" Language: mbsync setup files
" Maintainer: Stephen Gregoratto <themanhimself@sgregoratto.me>
" Last Change: 2018-03-13
" Filenames: mbsyncrc
" Version: 0.2
" Licence: GPLv3+
"
" Note: This config borrows heavily from msmtprc.vim
" by Simon Ruderich and Eric Pruitt
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
" OPTIONS - Ripped directly from mbsync(1)
" All Stores
syntax match mbsyncOption /^\<\(Path\|MaxSize\|MapInbox\|Flatten\|Trash\|TrashNewOnly\|TrashRemoteNew\)\>/
" Maildir Stores
syntax match mbsyncOption /^\<\(MaildirStore\|AltMap\|Inbox\|InfoDelimiter\|SubFolders\)\>/
" IMAP4 Account
syntax match mbsyncOption /^\<\(IMAPAccount\|Host\|Port\|Timeout\|User\|Pass\|PassCmd\|Tunnel\|AuthMechs\|SSLType\|SSLVersions\|SystemCertificates\|CertificateFile\|ClientCertificate\|ClientKey\|PipelineDepth\|DisableExtension.*\)\>/
" IMAP Stores
syntax match mbsyncOption /^\<\(IMAPStore\|Account\|UseNameSpace\|PathDelimiter\)\>/
" Channels
syntax match mbsyncOption /^\<\(Channel\|Master\|Slave\|Pattern\|Patterns\|MaxSize\|MaxMessaages\|ExpireUnread\|Sync\|Create\|Remove\|Expunge\|CopyArrivalDate\|SyncState\)\>/
" Groups
syntax match mbsyncOption /^\<\(Group\|Channel\)\>/
" Global
syntax match mbsyncOption /^\<\(FSync\|FieldDelimiter\|BufferLimit\)\>/
" VALUES
" Options that accept only yes|no values
syntax match mbsyncWrongOption /^\<\(TrashNewOnly\|TrashRemoteNew\|AltMap\|SystemCertificates\|UseNameSpace\|ExpireUnread\|CopyArrivalDate\|FSync\) \(yes$\|no$\)\@!.*$/
" Option SubFolders accepts Verbatim|Maildir++|Legacy
syntax match mbsyncWrongOption /^\<\(SubFolders\) \(Verbatim$\|Maildir++$\|Legacy$\)\@!.*$/
" Option SSLType accepts None|STARTTLS|IMAPS
syntax match mbsyncWrongOption /^\<\(SSLType\) \(None$\|STARTTLS$\|IMAPS$\)\@!.*$/
" Option SSLVersions accepts SSLv3|TLSv1|TLSv1.1|TLSv1.2
syntax match mbsyncWrongOption /^\<\(SSLVersions\) \(SSLv3$\|TLSv1$\|TLSv1.1$\|TLSv1.2$\)\@!.*$/
" Option Sync
syntax match mbsyncWrongOption /^\<\(Sync\) \(None$\|Pull$\|Push$\|New$\|ReNew$\|Delete$\|Flags$\|All$\)\@!.*$/
" Options Create|Remove|Expunge accept None|Master|Slave|Both
syntax match mbsyncWrongOption /^\<\(Create\|Remove\|Expunge\) \(None$\|Master$\|Slave$\|Both$\)\@!.*$/
" Marks all wrong option values as errors.
syntax match mbsyncWrongOptionValue /\S* \zs.*$/ contained containedin=mbsyncWrongOption
" Mark the option part as a normal option.
highlight default link mbsyncWrongOption mbsyncOption
" SPECIALS
" Email Addresses (yanked from esmptrc)
syntax match mbsyncAddress /[a-z0-9_.-]*[a-z0-9]\+@[a-z0-9_.-]*[a-z0-9]\+\.[a-z]\+/
" Host names
syntax match mbsyncHost /[a-z0-9_.-]\+\.[a-z]\+$/
" Numeric values
syntax match mbsyncNumber /\<\(\d\+$\)/
" File Sizes
syntax match mbsyncNumber /\d\+[k|m][b]/
" Master|Slave stores
syntax match mbsyncStores /:[^-].*:[^-]*$/
" Strings
syntax region mbsyncString start=/"/ end=/"/
syntax region mbsyncString start=/'/ end=/'/
" Comments
syntax match mbsyncComment /#.*$/ contains=@Spell
" File/Dir paths - Neovim exclusive
if has ('nvim')
syntax match mbsyncPath "~\%(/[^/]\+\)\+"
endif
highlight default link mbsyncAddress Constant
highlight default link mbsyncComment Comment
highlight default link mbsyncHost Constant
highlight default link mbsyncNumber Number
highlight default link mbsyncOption Type
highlight default link mbsyncPath Constant
highlight default link mbsyncStores Identifier
highlight default link mbsyncString String
highlight default link mbsyncWrongOptionValue Error
let b:current_syntax = "mbsync"
@bronzehedwick
Copy link

Great script! Can you create a regular Github repo for it, so package managers can access it more easily? Thanks!

@LEI
Copy link

LEI commented Jul 15, 2018

Indeed! If you go the extra mile you may want to use autocmd BufNewFile,BufRead *.mbsyncrc set filetype=mbsyncrc in ftpdetect and might as well setlocal commentstring=#\ %s in ftplugin.

Also, check out my fork to see what the default vint linter has to say:

  • explicit namespace for v:version
  • stripped trailing whitespaces
  • switched to single quotes

@chunkhang
Copy link

I've taken the liberty of creating the plugin based on the fork by @LEI: https://github.com/chunkhang/vim-mbsync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment