46

I have a large JSON file. It is not easy to work on all file at a time. I want to fold some content so that I can work on a section of JSON file.

E.g.:

{
  obj: {+}, // folded section
  obj:{
        // unfolded section
     }
}

Is it possible to fold JSON structure in Vim?

63

Yes, it is possible. A minimal setup would be:

:set filetype=json
:syntax on
:set foldmethod=syntax
6
  • 2
    what keystroke needed to fold and unfold a section?
    – WitVault
    Dec 9 '16 at 11:04
  • 8
    :h fold-commands - zo - open and zc - close
    – grodzik
    Dec 9 '16 at 11:46
  • 9
    za - toggle fold
    – alecdwm
    Aug 12 '19 at 7:26
  • FWIW: This isn't enabling folding for me. "E490: No fold found".
    – spazm
    Nov 3 '20 at 20:40
  • 1
    @spazm: So you can probably ask a new question here, describe what OS you're using, what exact editor, what version, all the steps you're doing, all the info that could be helpful.
    – grodzik
    Nov 5 '20 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.