I have been trying to set up code folding in Vim for JavaScript but the default isn't working correctly. I have little experience with Vim and have a hard time understanding the help files (as proven by my failed attempts at doing this myself).
The JavaScript code that creates problems more or less looks like this:
var x = {};
x.prototype = (function () {
// Variable declarations...
var y;
// Other content...
y = (function () {
// Stuff...
}());
// Other content continues... eg:
return {
// Other stuff...
};
}());
When I fold y = (function () {}());, it looks like this:
var x = {};
x.prototype = (function () {
// Variable declarations...
var y;
// Other content...
y = (function () {----------------------------------...
Notice how the rest of the function disappears! It should actually be looking like this:
var x = {};
x.prototype = (function () {
// Variable declarations...
var y;
// Other content
y = (function () {----------------------------------...
// Other content continues... eg:
return {
// Other stuff...
};
}());
Like I said above I tried playing around with the syntax file but it only broke the folding.
For convenience, here is the code folding section of the JavaScript syntax file:
if exists("javaScript_fold")
syn match javaScriptFunction "\<function\>"
syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend
syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>"
syn sync match javaScriptSync grouphere NONE "^}"
setlocal foldmethod=syntax
setlocal foldtext=getline(v:foldstart)
else
syn keyword javaScriptFunction function
syn match javaScriptBraces "[{}\[\]]"
syn match javaScriptParens "[()]"
endif
syn sync fromstart
syn sync maxlines=100
I have 3 questions:
- Is it possible to fix the code folding through
~/.gvimrc? - How do I fix the code folding?
- How do I make the folded code take this form
y = (function () { ... }());?