Question

Hello I am coding R and would like to be able to fold function In R I code function like this:

myFnName <- function(some, args){
    #some description or not
    some code
}

My question is how can I code a function that will fole the function like automatically when hitting some key even inside the function. I know I can set fdm=manual but then I have to do it on the 100's of function I have.

myFnName <- function(some, args){
+----------------
Was it helpful?

Solution

What "did not work" with indent?

Both syntax and indent work, but your problem may be that both methods don't take comments into account so they don't do anything for your sample (they see only one line so there's nothing to fold).

As soon as you have more than one line of actual code, za, zM, zR and friends work perfectly.

Another method worth trying is marker, using :set foldmarker={,} allows you to turn:

myFnName <- function(some, args){
    #some description or not
    some code
}

into:

+--  4 lines : myFnName <- function(some, args)--------

with a simple za.

Anyway, I recommend these two vimcasts if you want more control:

OTHER TIPS

Check if there's a plugin that does that.

Read the help on how to write a custom folding function for the R filetype: :h 'foldexpr', :h fold-expr.

Read the in-depth tutorial on custom folding in Learn Vim Script the Hard Way by Steve Losh: "Advanced Folding".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top