VIM 文本文件的语法高亮

VIM syntax highlighting of text files

如果文件的第一个字符是 #

Vim 用于将纯文本文件 (*.txt) 语法高亮显示为 conf 文件。但是在我更新到8.0.3之后,这个功能就没有了。 除了提到的解决方案 here 之外,还有其他方法可以解决此问题吗?即不修改文件。

function SetConfType()
  if !empty(matchstr(getline('1'), '^#\s.*'))
    set filetype=conf
  endif
endfunction

autocmd  BufEnter *.txt call SetConfType()

更新:

这个单行本不需要功能。更优雅一点。

au BufRead * if getline(1) =~ '^#\s.*' | setlocal ft=javascript.flow | endif