As it seems, no builtin solution exists for your problem.
Origami (available from MELPA) can do it for you, although it does some strange things for arrays of objects:
- prop1: Value 1
prop2: Value 2...
Here, the ellipsis is Origami’s marker to show there’s hidden text. This is probably because, as the README says:
Anything not in this list [of supported modes] will be folded using indentation. This works surprisingly well for most major-modes and is great for folding text.
Origami, however, doesn’t have hardcoded key bindings, so here’s how i install it (YMMV):
(use-package origami
:demand
:config
(define-prefix-command 'origami-mode-map)
(define-key ctl-x-map (kbd "z") 'origami-mode-map)
(global-origami-mode)
:bind
(:map origami-mode-map
("o" . origami-open-node)
("O" . origami-open-node-recursively)
("c" . origami-close-node)
("C" . origami-close-node-recursively)
("a" . origami-toggle-node)
("A" . origami-recursively-toggle-node)
("R" . origami-open-all-nodes)
("M" . origami-close-all-nodes)
("v" . origami-show-only-node)
("k" . origami-previous-fold)
("j" . origami-forward-fold)
("x" . origami-reset)))
This makes C-x z c
close a node, and C-x z o
open it again.