:best of Vim

Showcasing the top Vim plugins, tips and tricks.

What is Vim?

Vim is a text editor for programmers, power users & command-line junkies.

What is :best of Vim?

:best of Vim showcases the best plugins, extensions & tips for making the most of Vim.

It was built for NoVIMber 2011.

Learn more...

Follow

JavaScript Code Folding

It's a little surprising that Vim doesn't support code-folding for JavaScript out-of-the-box. But it's easy to add. Put this into a ~/.vim/ftplugin/javascript.vim file:

" Code Folding
syntax region foldBraces start=/{/ end=/}/ transparent fold keepend extend
setlocal foldmethod=syntax
setlocal foldlevel=99

Breakdown

The first line defines a folding region as anything between {}s.
The second switches folding on.
The third defaults to all folds being open. Change 99 to 0 to start with everything closed, if you prefer.

See :help syn-region, :help foldmethod and :help foldlevel for more.

Comments...