当我将autocmd
与FileType
放入我的.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
,而不是按类型设置。
答案 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.