2012-07-30 48 views
1

注:重寫了原來的問題,以反映給予適當的解決方案。GVIM(Linux版)與R-插件不承認有意見.R文件

VIM(ubuntu的12.04瓦特/ R-插件),如下所示不識別.R或.R文件作爲與該文件中的註釋安裝的r插件R上的文件。

# comment 
x <- 2 
x 

沒有評論,一切工作正常。 我的〜/ 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 
+1

你能提供兩個示例文件,一個工程,一個是不? – Thor 2012-07-30 15:20:58

+0

謝謝Thor,在嘗試爲這個例子創建兩個等效文件後,我意識到有問題的文件以評論開始。我將添加到上面的問題來重新創建問題。 – JimmyT 2012-07-30 16:01:55

回答

1

多種文件類型似乎是使用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或雷博爾文件,您可以覆蓋檢測:

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

我的〜/ 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 難道不應該解決這個問題? – JimmyT 2012-07-30 16:19:29

+0

添加到原始問題,以便格式更好顯示。 – JimmyT 2012-07-30 16:24:33

+0

標誌着這是正確的,因爲它解決了這個問題......我的實際的解決辦法是改變「setfiletype R」到「setfiletype = R」,但上面會很好的工作。 – JimmyT 2012-07-30 16:58:55