Vimscript:未加载文件类型

时间:2017-11-11 21:17:18

标签: vim cygwin

我不熟悉vimscript并了解它是如何工作的。我想将其安装到我的配置中:https://github.com/vim-scripts/Twee-Integration-for-Vim我将它直接放入我的.vim目录(可能是我出错的地方)。

它有一个~/.vim/ftdetect/twee.vim文件,我对它进行了一些修改。它看起来像这样:

" markdown filetype file
if exists("did\_load\_filetypes")
        echom "I put this here"
        finish
endif

augroup twee
        au! BufRead,BufNewFile *.twee,*.tw   setfiletype twee
        autocmd BufRead,BufNewFile *.twee,*.tw    compiler twee
augroup END

我自己补充说。每当我打开一个带有.twee扩展名的文件时,它就会打印出那个回声。但是当文件打开时,如果我输入:set filetype?,则会打印出来:filetype=

我做错了什么?如何运行此自动组?顺便说一句,如果我在本地缓冲区中:set filetype=twee,语法突出显示正常。

1 个答案:

答案 0 :(得分:0)

答案在这里:http://vim.1045645.n5.nabble.com/FTDetect-td1151042.html

有许多不同的方法可以进行文件类型检测;
你混淆了其中两个。

我并不完全了解ftdetect目录的工作原理,但是 :help ftdetect表示如果要添加文件类型 通过将文件放入' ftdetect'来检测新文件类型 目录,该文件应仅包含 自动命令,例如,

    au BufRead,BufNewFile *.wibble set filetype=wibblewobble

请注意!之后没有au且命令是 set filetype,而不是`setfiletype。另请注意,帮助条目表示:

...there is no "augroup" command, this has already been
done when sourcing your file.

另一方面,如果通过创建文件类型检测来添加文件类型检测 自己的~/.vim/filetype.vim文件,然后你会把那个文件放进去 您在上面使用的命令,即

    if exists("did_load_filetypes")
      finish
    endif
    augroup filetypedetect
      au! BufRead,BufNewFile *.wibble setfiletype wibblewobble
    augroup END