Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax folding in JavaScript files does not work in Vim

I've started using Vim 7.4 on Ubuntu and am very pleased with it but there is just one thing driving me crazy: code folding doesn't work (at least for JavaScript)!

The syntax is automatically set to JavaScript when a js file is opened and syntax highlight works so I don't get it. The foldmethod is initially set to "manual" and setting it to "syntax" doesn't make a difference, which puzzles me. I did add let javaScript_fold=1 to my .vimrc file.

Any clue? I'd be very grateful. Thanks!

like image 831
A.hel Avatar asked Oct 20 '25 13:10

A.hel


1 Answers

Just had this same issue answered on Vim Stack Exchange, and the answer is that if you do use the stock syntax/javascript.vim file, then you have to set

    vv
let g:javaScript_fold = 1
    ^^

The difference between the command in the question and here is the g: part (highlighted above). I'm new to Vim scripting, but I believe the difference is that let javaScript_fold=1 sets a script-local variable, making it confined to your .vimrc file, and the example above makes it global (which seems to be confirmed by this Stackoverflow thread). See more on this at section 41.2 Variables in :help usr_41.txt and :help internal-variables.

This Reddit thread was also enlightening; it's not JavaScript-related but the folding seems to be useful for JS files as well.

like image 121
toraritte Avatar answered Oct 22 '25 04:10

toraritte



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!