I'm working with vim on my linux machine and need code folding to work for R. I have the Vim-R-plusing2 installed to enable passing 开发者_如何转开发code from vim into an R session, but the folding does not work when foldmethod=syntax. How do I get folding for R working?
What to do:
You need to add the following code to your vimrc file:
let r_syntax_folding = 1
Why it works:
This option changes how the Vim-R plugin loads.
This code is copied from syntax/vim.r
and shows how the setting above changes what code is run:
" Error
if exists("g:r_syntax_folding")
syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold
syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold
syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold
else
syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
endif
Quoting from the help
10.8. Fold setup~
Vim has several methods of folding text (see |fold-methods| and |fold-commands|). To enable the syntax method of folding for R files, put in your |vimrc|:
let r_syntax_folding = 1
With the above option, Vim will load R files with all folds closed. If you prefer to start editing files with all folds open, put in your |vimrc|:
Something similar, but referring to markdown, anyway you may find some useful info there.
You may try even :help folding
for detailed descriptions.
精彩评论