VIM语法高亮显示文本文件

时间:2019-03-19 17:12:39

标签: vim syntax-highlighting

Vim用于将纯文本文件(*.txt)语法突出显示为conf文件,如果文件的第一个字符是#。但是,当我更新为8.0.3之后,此功能便消失了。 除了提到的here解决方案之外,还有其他方法可以解决此问题吗?即无需修改文件。

1 个答案:

答案 0 :(得分:2)

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

autocmd  BufEnter *.txt call SetConfType()

更新:

此oneliner不需要功能。有点优雅。

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