为什么FileType有效,BufRead,BufNewFile没有 - VIM?

时间:2015-11-06 06:46:22

标签: vim

当我将autocmdFileType放入我的.vimrc时,它确实有效。

autocmd FileType ctp setlocal commentstring=#test\ %s

当我致电<leader>cc |NERDComComment|时,它确实有效并将#test作为评论。但是我必须首先通过set ft=ctp更改文件类型,但它会混淆我的语法高亮,这就是为什么我希望能够通过文件扩展名来设置它。

但是当我尝试使用BufRead,BufNewFile时,它无法正常工作

autocmd BufRead,BufNewFile *.ctp setlocal commentstring=#test\ %s

如何按文件扩展名设置setlocal commentsting,而不是按类型设置。

1 个答案:

答案 0 :(得分:1)

.ctp属于php filetype组。所以,如果您希望alternative commenting style

let g:NERDCustomDelimiters = {
   \ 'php': { 'left': '//', 'leftAlt': '#test ' }
   \ }

.vimrc中。要更改为备用评论样式,请使用<Leader>ca

其他方法的问题是NERD评论者uses a filetype and its own set of rules to set its commenting style. If it is not found, then it uses &cms option.