带有r-plugin的gvim(linux)无法识别带有注释的.r文件



注意:重写原始问题以反映给出的正确解决方案。

vim(ubuntu 12.04 w/r-plugin)无法将.r或.r文件识别为r文件,安装了r-plugin并在文件中添加了注释,如下所示。

# comment
x <- 2
x

没有评论,一切都很好。my~/.vim/filetype.vim读取:

augroup filetypedetect
  au! BufRead,BufNewFile *.r         setfiletype r
  au! BufRead,BufNewFile *.R         setfiletype r
  au! BufRead,BufNewFile *.Rnw       setf noweb
augroup END

多个文件类型似乎使用R扩展名。我在$VIMRUNTIME/filetype.vim:中发现了这个

" Rexx, Rebol or R
au BufNewFile,BufRead *.r,*.R           call s:FTr()
func! s:FTr()
let max = line("$") > 50 ? 50 : line("$")
for n in range(1, max)
    " Rebol is easy to recognize, check for that first
    if getline(n) =~? '<REBOL>'
    setf rebol
    return
    endif
endfor
for n in range(1, max)
    " R has # comments
    if getline(n) =~ '^s*#'
    setf r
    return
    endif
    " Rexx has /* comments */
    if getline(n) =~ '^s*/*'
    setf rexx
    return
    endif
endfor
" Nothing recognized, assume Rexx
setf rexx
endfunc

因此,你需要在文件中有注释,以便Vim正确检测R.

如果您从未使用Rexx或Rebol文件,您可以覆盖检测:

au BufNewFile,BufRead *.r,*.R setf r

最新更新