Thursday, March 23, 2017

VIM folding when viewing large JSON files

I'm been lamenting the lack of a shell-based editor that has folding (aka collapsing) built in.  On a whem, I Googled if Vim could do it and behold, it can, it's native and it's straightforward!

When opening a file, give Vim some hints (might not be necessary)

:set filetype=json
:syntax on

And tell Vim to turn on folding

:set fdm=syntax

At this point, everything will be folded/collapsed.  To unfold, the current marker, use zo.  To fold the current line, is zc.  To unfold all, zO to fold all, zC

Nice elegant solution

Further documentation I'm looking at to understand other features.

:help fold-commands
:help fdm