I am a fan of vim's folding feature, but I have encountered some challenges when trying to fold backbone models, views, and collections. This is because backbone does not follow the traditional prototype syntax, but instead uses a .extend() based syntax.
Is there a way for me to configure vim to fold code like this:
var MyView = Backbone.View.extend({
somesuch: 'stuff'
});
To fold into something like this:
MyView = Backbone.View.extend({...}) --------------------------------------------
Are there any useful plugins or tweaks that I can add to my .vimrc file?
EDIT1:
I attempted to solve this by creating a file in .vim/after/ftplugin/javascript/folding.vim with the following content:
syntax region foldBraces start=/\.extend({/ end=/});/ transparent fold keepend extend
setlocal foldmethod=syntax
However, it did not work as expected because it incorrectly matched the first occurrence of });
as the end of the fold regardless of indent level. For instance, in a scenario like this:
var MyView = Backbone.View.extend({ // THIS STARTS THE FOLD
initialize: function() {
_.each(someVar, function(item) {
console.log(item);
}); // THIS WILL END THE FOLD
}
}); // THIS __SHOULD__ END THE FOLD