Skip to content

Latest commit

 

History

History
67 lines (41 loc) · 2.17 KB

File metadata and controls

67 lines (41 loc) · 2.17 KB

Since you are working with a Protocolorizer that generates HTML, but also likely need to view the raw JSON payloads within Gvim (Vim), you can achieve excellent expand/collapse functionality using Vim's built-in folding features.

Here are the best ways to handle JSON in Gvim:

1. The Built-in Way (Syntax Folding)

Vim can fold code based on the syntax rules (braces {} and brackets []).

  • Command: Set the fold method to syntax.
:set foldmethod=syntax
  • Command: Ensure the filetype is set to JSON (enables the specific syntax rules).
:set filetype=json

2. Standard Gvim Fold Shortcuts

Once folding is enabled, use these keyboard shortcuts to navigate your JSON:

Shortcut Action
za Toggle (Open/Close) the fold at the current cursor position.
zc Close the current fold.
zo Open the current fold.
zM Close All (Collapse everything to the root).
zR Open All (Expand the entire file).
zj Move cursor to the next fold.
zk Move cursor to the previous fold.

3. Making it Readable (Auto-Format)

Gvim's folding is much easier to use if the JSON is "Pretty Printed" (one key per line). If your input file is a single long line, run this filter command inside Gvim:

:%!python -m json.tool

This uses your system's Python to format the JSON, making the {} align vertically for perfect folding.

4. Recommended .vimrc Settings

To make this behavior permanent for all JSON files, add this to your configuration:

" Enable folding for JSON files automatically
autocmd FileType json setlocal foldmethod=syntax
" Start with all folds open (optional)
autocmd FileType json setlocal foldlevel=99

Pro Tip for A2UI Work:

Since A2UI components can result in massive arrays, using zM (Collapse All) followed by zo (Open current) on the components key allows you to quickly find a specific component ID without scrolling through thousands of lines of UI properties.

Would you like me to show you how to map these fold commands to the Spacebar in Gvim for even faster navigation?