cygwin: vim custom syntax highlighting not working

Issue

I have a set of log files that have a standard format. I’ve created a custom syntax file for these logs, and it works fine on a linux system.

however, I can’t get it to work in cygwin. I have in my home directory the following .vimrc file:

au BufRead,BufNewFile rc.log* set filetype=rclog
au! Syntax rclog source ~/.vim/log.vim

syntax on

and in ~/.vim/ i have log.vim:

:syn region logTime start=+^\d\{4}-\d\{2}-\d\{2} \d\{2}:\d\{2}:\d\{2}+ end=+ +me=e-1
:syn keyword logError ERROR skipwhite nextgroup=logThreadName
:syn keyword logWarn WARN skipwhite nextgroup=logThreadName
:syn keyword logInfo INFO skipwhite nextgroup=logThreadName
:syn keyword logDebug DEBUG skipwhite nextgroup=logThreadName
:syn keyword logAlways ALWAYS skipwhite nextgroup=logThreadName
:syn keyword logConfig CONFIG skipwhite nextgroup=logThreadName
:syn match logThreadName "\[\S\+\]" contained nextgroup=logClassName
:syn match logClassName " \S\+:" contained nextgroup=logLineNumber
:syn match logLineNumber "\d\+" contained

hi def logError ctermfg=white ctermbg=red
hi def logWarn ctermfg=black ctermbg=yellow
hi def logInfo ctermfg=green
hi def logDebug ctermfg=blue
hi def logAlways ctermfg=yellow
hi def logConfig ctermfg=cyan
hi def logTime ctermfg=white ctermbg=blue
hi def logThreadName ctermfg=magenta
hi def logClassName ctermfg=cyan
hi def logLineNumber ctermfg=yellow
hi link cConstant NONE

I’ve tried executing :source ~/.vimrc to no avail. My log files always show up without syntax highlighting. Files with a filetype that has highlighting built in (such as .py or .c) work fine.

Solution

Don’t use :au! Syntax; instead, move ~/.vim/log.vim to ~/.vim/syntax/rclog.vim; it’ll then be read automatically based on your filetype detection:

au BufRead,BufNewFile rc.log* set filetype=rclog

You can verify and troubleshoot with :scriptnames, or via :20verbose setlocal syntax=rclog.

Answered By – Ingo Karkat

Answer Checked By – Mary Flores (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.